I just started working with VS 2005 Express (C#). I amtrying to set progressbar.style to "Continuous" in a simple Form, and doesn't seem to be working:
progressBar1.Style = ProgressBarStyle.Continuous;
This is supposed to give you a smooth incrementing progressbar. But the result is the same as the default Block style.
Is this a known bug or is my code wrong?
Thanks.
|
| LalithP Friday, February 17, 2006 1:55 PM |
It is easily fixable, check this thread. Here's a somewhat cleaner solution:
using System; using System.Windows.Forms;
public class ContinuousProgressBar : ProgressBar { public ContinuousProgressBar() { this.Style = ProgressBarStyle.Continuous; } protected override void CreateHandle() { base.CreateHandle(); try { SetWindowTheme(this.Handle, "", ""); } catch { } } [System.Runtime.InteropServices.DllImport("uxtheme.dll")] private static extern int SetWindowTheme(IntPtr hwnd, string appname, string idlist); }
|
| nobugz Thursday, September 13, 2007 6:04 PM |
The "Continuous" style of the progress bar only works if Windowsvisual styles are not enabled. In other words, if your application has the "XP Look", the continuous style is not shown.
If the application is run with Windows visual styles off, or on a platform such as Windows 2000, continuous should still work. |
| ShadowChaser Wednesday, February 22, 2006 8:55 PM |
So basically it comes down to progressbarstyle continuous being completely useless because it's not truely cross platform. You have to cripple the visual stylings of XP, which few people will have done, and is not the default, to get this function to actually work. BackColor and ForeColor for progressbars are the same way. Completely pointless because rarely anyone will ever properlysee what Visual Studio allowed you to create. Time to look for a completely different widget for me, I "had" to have continuous or my application is completely pointless. The block look does not have the resolution when my progress bars are super tiny (It's a monitoring program. Small window that sits in the corner with tiny tiny progress bars that display CPU/memory usages from multiple remote servers).
Or... does Visual Studio allow you to turn off visual styles for just your application? Or is it a setting that only the operating system has set on a machine by machine basis? Because if "I" have control over the visual style of just my application, and it's not something the user has to have their operating system set for, I'll just go with the 2000 look so that my application is at all useful. |
| danglen Thursday, September 13, 2007 3:50 PM |
There's a couple good articles at code project on progress bars. Here's one of them: http://www.codeproject.com/cs/miscctrl/colorprogressbar.asp |
| MrBones Thursday, September 13, 2007 4:57 PM |
In the main (usually in Program.cs)method comment out the line that enables visual styles:
Application.EnableVisualStyles();
to
//Application.EnableVisualStyles();
This will disable the use of visual styles and the progress bar will work on continuous style. |
| Fábio Franco Thursday, September 13, 2007 5:00 PM |
It is easily fixable, check this thread. Here's a somewhat cleaner solution:
using System; using System.Windows.Forms;
public class ContinuousProgressBar : ProgressBar { public ContinuousProgressBar() { this.Style = ProgressBarStyle.Continuous; } protected override void CreateHandle() { base.CreateHandle(); try { SetWindowTheme(this.Handle, "", ""); } catch { } } [System.Runtime.InteropServices.DllImport("uxtheme.dll")] private static extern int SetWindowTheme(IntPtr hwnd, string appname, string idlist); }
|
| nobugz Thursday, September 13, 2007 6:04 PM |
OMG Hans, how do you figure all that stuff out? I am a big fan, if one day I get to know what you know,
I will be a happy programmer |
| Fábio Franco Thursday, September 13, 2007 7:53 PM |
Perfect solution. It worked without subclassing or anything of the sort. |
| D. Casals Friday, August 07, 2009 7:00 PM |