Ads by Lake Quincy Media
| Next Tip?
Home » Asp.net, Tutorial

Progress Bar demo application

3 August 2009 4,747 views 3 Comments
1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 4.67 out of 5)
Loading ... Loading ...

Hi All, I am Developing this Application just to help a newbie in the technology and even many of my students have asked me for the application which will demonstrate them how to use a progress bar in C#.net for a windows application. So here is a small application which will solve the purpose. So Here Is the application and description how to develop the application.

1. Create a New Project in VS 2008 or above as per your convince I have installed VS 2008 so I am using that if you want to use VS 2005 you can even go with that also. For now VS2008

2. Create New Project : Select Windows Forms Application under the Visual C# tab and give the name to the project as prjProgressBar.

3. Now Place The ProgressBar Control and the Button Tool on the form from the tools box as shown in the figure below. 4. Set the following Properties of the progress bar:

  • Minimum =0 (By Default). This value will specify the lower bound for the progress bar.
  • Maximum =500 (Default value is 100). This is the upper bound value of the progress bar when progress is complete.
  • Step= 5 (Default is 10) This value is the value by which the progressbar will increase the current value with the next step when performstep function will be called. (in this case 500/5=100 i.e. in ten steps we will complete the progressbar.)
  • Value =0 (Default is 0) This will set or get the current value of the progressbar.
  • Style is the cosmetic property of the control default is blocks you may change it to marquee or continues. I am not changing it.
  • MarqueeanimationSpeed=100 (default is also 100): this is the speed in milisseconds set for the animation of the progressbar.

Now On the button click event we will start the progress bar and show a message at final step that in how many steps we have completed the progress bar. The code will be:
<code>private void button1_Click(object sender, EventArgs e)

{

int i = 0;

while (progressBar1.Value &lt; progressBar1.Maximum )

{

progressBar1.PerformStep();

i++;

}

MessageBox.Show("Step : " + i);

}

Now The above code I have written on the button click so you can write it at any place you needed. Suppose You want that as the data is begin added in the database then you need to perform a step in the database you can do that. But in that case you should set the maximum value of the progressbar to the total no. of records to be inserted and this will be set by the code at the event where you have calculated the total no. of records. with the help of this line. progressBar1.Maximum=NoRecs; and the step value should be 1 and when the insertion is completed in the database then use progressBar1.PerformStep(); line of code there. The Sample Code is attached.


Thanks and Regards
Meetu Choudhary
MVP || My Blog || MySite || My Forums

Popularity: 36%

Post to Twitter Tweet This Post

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

Ads by Lake Quincy Media

3 Comments »

  • shuby said:

    very useful code

  • Hiren Patel said:

    Hi I like this progress bar code.
    But I just want to alert you about this code that on the button start click even you forgot line of the code for start the progress bar.
    in your attachment file we get the code correct but in your post we found incomplete code.
    please check it out and do correction.

    best regards
    Hiren Patel (MCA software professional)

  • Meetu Choudhary (author) said:

    Thanks Hiren For Pointing. I have Added The Lines In the Post Too.

    ?

Leave your response!

You must be logged in to post a comment.

Get Adobe Flash playerPlugin by wpburn.com wordpress themes