Click here to Skip to main content
Click here to Skip to main content

Tagged as

Go to top

Load an Image from Internet to PictureBox control and Track the Loading Progress

, 5 Jan 2011
Rate this:
Please Sign up or sign in to vote.
How do you load an Image from the internet into a picture box control. How will you track the loading progress
Have a form with a Picture Box control, a Buttton to load the image and a Progress Bar control. Add a Label next to the progress bar to show the % loaded.
 
The code below loads the Image from internet:
//Image_003: Load the Image from the Internet
private void btnLoadInternet_Click(object sender, EventArgs e)
{
    try
    {
        if (radNormal.Checked == true)
            pict.Load("http://www.stanford.edu/~jbaugh/saw/studentphoto/Scenery/CampsBaySunset.JPG");
        else
        {
            pict.WaitOnLoad = false;
            pict.LoadAsync("http://www.stanford.edu/~jbaugh/saw/studentphoto/Scenery/CampsBaySunset.JPG");
        }
    }
    catch
    {
        MessageBox.Show("Check that Internet Connection is available");
    }
}
 
Now provide the handler for the LoadProgressChanged event of the Picture box control. Unlike load method, the LoadAsync will raise the LoadProgressChanged event when some amount of image bits are downloaded from the http path. Inside the handler, we will use the event argument to decide how much of image is loaded. And the progress bar value is set with the percentage of completion retrieved from the event argument. Also the label control shows the number of percentage.
 
//Progress_001: Increment the value of the progress bar to show the image
//Load progress
private void pict_LoadProgressChanged(object sender, ProgressChangedEventArgs e)
{
    progLoadStatus.Value = e.ProgressPercentage;
    lblProgress.Text = e.ProgressPercentage.ToString() + "%";
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Sivaraman Dhamodharan
Software Developer iSOFT
India India
I am working as software engineer in iSOFT R&D. I have been come accross C++,MFC, .net technologies. I do like playing video games, reading books.
 

Web: www.mstecharticles.com


Comments and Discussions

 
Generallaveenadeeps, your vote reason and comment is contradicting ... Pinmembersirama20043-Jan-11 2:09 
GeneralReason for my vote of 1 nice Pinmemberlaveenadeeps28-Dec-10 17:03 
GeneralThanks Walt and Krish Pinmembersirama200428-Dec-10 0:53 
GeneralThanks! I wasn't aware of that particular event. PinsubeditorWalt Fair, Jr.27-Dec-10 13:24 
GeneralReason for my vote of 4 Nice event to know on Picture box. Pinmemberkrishnaraj4026-Dec-10 19:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 5 Jan 2011
Article Copyright 2010 by Sivaraman Dhamodharan
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid