question

UriF-1045 avatar image
0 Votes"
UriF-1045 asked DanielZhang-MSFT commented

ProgressBar style in WinForm

I tried to use ProgressBar in VS 2015 (VB.NET & C#) Community. It works OK except Style. Doesn't matter if I use "Continuous" or "Blocks" style I get "Continuous" style. I also tried in VS 2017 Community and I got the same behavior. It is strange. I downloaded one sample C# project and I am able to select between "Continuous"and "Blocks" styles. I use Windows 10 x64 20H2. I understand if "Blocks" would be disabled but I was able to run a project where everything works OK.


You understand that I use absolutely simple code. I can use "Continuous" style but I like I prefer "Blocks" style.

windows-forms
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

After I posted this question I tried to comment out the EnableVisualStyles line and got "fragmented" ProgressBar style instead of "Continuous". I just ask if I can do it without this trick. You understand that I write my application just for myself. I use Progress Bar in tandem with Background Worker for long running processes and visual style is not critical. I tried different samples but i was not satisfied their behavior. I also not interested in third party controls. I thought that it is any trick to go around of this behavior. That's it.

0 Votes 0 ·

With visual styles disabled then Blocks works, otherwise it is not supported. Continuous is the same as documented in msdn.

With visual styles enabled only Marquee works correctly in Winforms. However there are some folks who say that setting the window theme for the control will allow continuous to work. I've never tried it myself but here's a sample post.

0 Votes 0 ·

I read this trick and instead of "Continuous" set "Blocks". As a result I got typical "Continuous" BUT instead of green color I got blue color. That's it.

0 Votes 0 ·

Hi @UriF-1045,
As cooldadtx said that you need to disable the use of visual styles.
And you can change the color of the ProgressBar to green through the ForeColor property.

 progressBar1.ForeColor = Color.Green;

Best Regards,
Daniel Zhang

0 Votes 0 ·

1 Answer

cooldadtx avatar image
0 Votes"
cooldadtx answered

ProgressBar is backed by the OS, like most Winforms controls. When visual styles are enabled, the default, then it uses the OS theming and blocks is not supported as shown here. To disable this you'd need to go to your Program.Main function and comment out the EnableVisualStyles line. However that reverts your app to the "Win95" look which is probably not what you want.



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.