C # picturebox load the image and display the progress bar

Source: Internet
Author: User

 

I have not tried to attach a network image when I used picturebox of winform. Code The loadasync method can be used to load images asynchronously, And the loadprogresschanged event can be used to get the current loading progress.

Put a picturebox control, a button, a progress bar control on the form, and use a label to display the current progress percentage. The Code is as follows:

Private Void Button#click ( Object Sender, eventargs E)

{
Try
{

Picturebox1.waitonload = False ;
Picturebox1.loadasync (
" Http://hiphotos.baidu.com/18826860/pic/item/c68220d54518d3ef562c841c.jpg " );

}
Catch
{

MessageBox. Show ( " Network Connection Failed " );
}
}

Add the loadprogresschanged event to picturebox, And the loadasync method will trigger this event. The current progress can be obtained from E. progresspercentage.

Private VoidPicturebox1_loadprogresschanged (Object 
Sender, system. componentmodel. progresschangedeventargs
E)
{
Progressbar1.value = E. progresspercentage;
Label1.text =
E. progresspercentage. tostring () +"%";
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.