Progress Bar in C#

I am very busy these days and not getting time to do readings or writing on my blog. But today i manged to get some time so i decided to write this simple tutorial. I am going to write that how progress bar works in C#, ProgressBar class is part of .NET framework. In this tutorial i am going to use three members of class ProgressBar Minimum,Maximum and Value.
So first create a C# Application and add progress bar control on your form, you can give it any name but i am naming it "pb" here. Add timer and name it as "tr".Now paste the following code in form load event

private void frmProgressbar_Load(object sender, EventArgs e)
{
pb.Minimum = 0; // set Minimum to 0
pb.Maximum = 100;// set Maximum t0 100
tr.Interval = 100;// timer ticks each 100 milliseconds
tr.Enabled = true; // start the timer
}

Now paste the following code behind Timer Tick Event

private void tr_Tick(object sender, EventArgs e)
{
if(pb.Value!=100) // check if value below 100 as it shud not be greater than maximum value
{
pb.Value += 5;// add 5 to the Progressbar current value
}
}
Thats it!! its done, isn't it simple? :P.I hope this will help you

0 comments:

Post a Comment