Displaying Progress in .NET

Whenever your users are waiting for something to complete, they’d probably like an idea on how long it is going to take, or at least how far along it is. Imagine downloading something without knowing how big it was, how much you had done, or how fast you were downloading. You’d just have to wait.

Progress Bars are rather easy to use. Let’s create a new project in Visual Studio.NET and get rolling!

Demonstrating simple progress, let’s add 2 labels, a Progress Bar, a command button, and a timer control. My form looks like this:

Set the Max of the progress bar to 1000000 (one million). Set the Interval on the timer to 100 and Enabled to FALSE. The command button’s code is simply:

‘Enable Timer

tmrLoad.Enabled = True

The timer’s code would be:

private void tmrLoad_Tick(object sender, System.EventArgs e)

{

prgLoading.Value = (prgLoading.Value + 10000);

lblProgress.Text = Convert.ToString(prgLoading.Value) + " / " + Convert.ToString(prgLoading.Maximum);

lblPercent.Text = Convert.ToString((prgLoading.Value/prgLoading.Maximum) * 100) + "%";

if (prgLoading.Value == prgLoading.Maximum)

{

tmrLoad.Enabled = false;

}

}

Run the program. You’ll see that there is nothing more to using a Progress Bar!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s