Here I will explain how to use progressbar control in windows application using c#.net.
Description
I have done one windows application in that I have one form like creating user and assigning permission to user during at the time of user creation and displaying that result in one data gridview for this process it’s taking time at that time user don’t know what is happening after button click for that reason I have used progressbar to give hint like processing. Previously I have implemented progress bar during postbacks in asp.net check that article here how to show progressbar during postbacks in asp.net .
We can specify different styles to progressbar we have three types of styles are available.
1. 1) Blocks
2. 2) Continuous
3. 3) Marquee
Blocks
This property Indicates progress by increasing the number of segmented blocks in a ProgressBar.
Continuous
This property Indicates progress by increasing the size of a smooth, continuous bar in a ProgressBar.
Marquee
This Property indicates progress by continuously scrolling a block across a ProgressBar in a marquee fashion.
To implement progressbar in windows applications follow these steps.
1) First open visual studio
2) Select New --> Projects --> Select Windows Form Application --> Give Name for that project
3) Now one form will open.
Open Toolbox in that select progressbar control and drag and drop it on your form same drag one button.
Here my requirement is if I click on button I need to register user and assign roles and showing result in this mean time I need to show the progressbar for that I have written following code in button click
This example shows progressbar during registration of all users
private void btnCreate_Click(object sender, EventArgs e) { // Set Minimum to 1 to represent the first file being copied. Progressbar1.Minimum = 1; // Set Maximum to the total number of Users created. Progressbar1.Maximum = dt.Rows.Count; // Set the initial value of the ProgressBar. Progressbar1.Value = 1; // Set the Step property to a value of 1 to represent each user is being created. Progressbar1.Step = 1; // Loop through all files to copy. for (int i = 1; i <= dt.Rows.Count; i++) { bool result=InsertUserdetails(Username); // Copy the file and increment the ProgressBar if successful. if(result== true) { // Perform the increment on the ProgressBar. Progressbar1.PerformStep(); } } } |
Here I will explain clearly what each step says
Progressbar1.Minimum = 1;
Progressbar1.Maximum = dt.Rows.Count;
Here Minimum and Maximum properties define the range of values that means how much time that progressbar we need display.
Minimum property is basically set to a value 0
Maximum property is typically set to value of indicating the completion of task.
After that Progressbar1.Value = 1;
This value property determines when to display the nextblock(Blocks) or increase the size of bar (Continuous).
Progressbar1.Step = 1;
Set the Step property to a value of 1 to represent each user is being created.
Progressbar1.PerformStep();
This method will increment the value of the ProgressBar as each user registered. After completion of user registration progress bar shows fully loaded.
I hope it helps you
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
19 comments :
Thanks for the post. It helps me a lot.
Thank you it helped a lot
No comments ... it's good.
Very Helpful
its useful
thanks a lot
what is dt
helpful info... Thanks
helpful...
Nice Wonderfull
Thanks a lot
hi suresh .. ur article was so good. but i have one doubt.. how to update a progressbar while application statup based on the database data loading...
help me
Thanks in Advance
is that any dynamic in winform based.I need progress bar till data is inserted.after that thread be dead or any other way is requested instead of thread.
helpful Page.... and also i am looking for the Progressbar with percentage sent, Please can u help regarding that....
I need to run progress bar according to timer, ie, if I put timer for one min, progress bar should run for one min.
How can I do that.
Please help me for that.
very nice..........
nice one , it helped me
i want progress bar when i click on button for some my own operation like transferring data or retrive data....when system loading that time i want progress bar...not like this as u given
Very useful thanks a lot
Note: Only a member of this blog may post a comment.