I'd like to do two things on my progress bar.
Any information about those two things I wonder how to accomplish will be greatfuly appreaciated!
Thanks.
You can update the percentage of progress displayed by using the setProgress(int) method, or by calling incrementProgressBy(int) to increase the current progress completed by a specified amount. By default, the progress bar is full when the progress value reaches 100.
Alliteratively you can try placing a Label control and placing it on top of the progress bar control. Then you can set whatever the text you want to the label.
OK, it took me a while to read all the answers and links. Here's what I got out of them:
Sample Results
The accepted answer disables visual styles, it does allow you to set the color to anything you want, but the result looks plain:
Using the following method, you can get something like this instead:
How To
First, include this if you haven't: using System.Runtime.InteropServices;
Second, you can either create this new class, or put its code into an existing static
non-generic class:
public static class ModifyProgressBarColor { [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)] static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr w, IntPtr l); public static void SetState(this ProgressBar pBar, int state) { SendMessage(pBar.Handle, 1040, (IntPtr)state, IntPtr.Zero); } }
Now, to use it, simply call:
progressBar1.SetState(2);
Note the second parameter in SetState, 1 = normal (green); 2 = error (red); 3 = warning (yellow).
Hope it helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With