Asynchronously Load an Image from a Url to a PictureBox

前端 未结 2 562
时光说笑
时光说笑 2020-12-19 23:08

I want to load image from the web on windows forms application, Everything is good and code works fine, but the problem is the app stop working until the loading goes to fin

2条回答
  •  别那么骄傲
    2020-12-19 23:44

    PictureBox control has built-in support for loading images asynchronously. You don't need to use BackgroundWorker or async/await. It also can load an image from a URL, so you don't need to use a web request.

    You can simply use the LoadAsync method or ImageLocation property of PictureBox. The value of WaitOnLoad property should be false, which is the default.

    pictureBox1.LoadAsync("https://i.stack.imgur.com/K4tAc.jpg");
    

    It's equivalent to:

    pictureBox1.ImageLocation = "https://i.stack.imgur.com/K4tAc.jpg";
    

提交回复
热议问题