WinForms:进度条的前景颜色在XP Luna上始终为绿色

时间:2022-03-13 13:19:36

The WinForms ProgressBar control allows its foreground color to be set. While this normally works fine, the foreground color setting seems to be ignored on XP when using the obnoxious Luna style: it is always green.

WinForms ProgressBar控件允许设置其前景色。虽然这通常可以正常工作,但在使用令人讨厌的Luna风格时,XP中的前景色设置似乎被忽略了:它始终是绿色的。

Similaraly, XP Luna seems to ignore the 'Style': Although I have set it to 'Continuous', the progress bar is always drawn with blocks.

Similaraly,XP Luna似乎忽略了'Style':虽然我将它设置为'Continuous',但进度条总是用块来绘制。

Is this supposed to be correct behavior? Is there a way to work around this?

这应该是正确的行为吗?有办法解决这个问题吗?

1 个解决方案

#1


To disable the Luna visual style, you can remove the call to Application.EnableVisualStyles() in the auto-generated Program class.

要禁用Luna视觉样式,可以在自动生成的Program类中删除对Application.EnableVisualStyles()的调用。

This will make all controls on forms created after that point to look like Windows 2000.

这将使在该点之后创建的表单上的所有控件看起来像Windows 2000。

You can conditionally call it depending on the OS, since Vista's visual styles respect the Style property, IIRC (can't test right now - my laptop died).

您可以根据操作系统有条件地调用它,因为Vista的视觉风格尊重Style属性,IIRC(现在无法测试 - 我的笔记本电脑死了)。


You can handle the rendering of the control manually via the Paint event or by deriving from the control and overriding OnPaint*().

您可以通过Paint事件手动渲染控件,也可以从控件派生并覆盖OnPaint *()。

You could also roll your own from scratch, since progress bars are rather simple.

你也可以从头开始自己动手,因为进度条很简单。

#1


To disable the Luna visual style, you can remove the call to Application.EnableVisualStyles() in the auto-generated Program class.

要禁用Luna视觉样式,可以在自动生成的Program类中删除对Application.EnableVisualStyles()的调用。

This will make all controls on forms created after that point to look like Windows 2000.

这将使在该点之后创建的表单上的所有控件看起来像Windows 2000。

You can conditionally call it depending on the OS, since Vista's visual styles respect the Style property, IIRC (can't test right now - my laptop died).

您可以根据操作系统有条件地调用它,因为Vista的视觉风格尊重Style属性,IIRC(现在无法测试 - 我的笔记本电脑死了)。


You can handle the rendering of the control manually via the Paint event or by deriving from the control and overriding OnPaint*().

您可以通过Paint事件手动渲染控件,也可以从控件派生并覆盖OnPaint *()。

You could also roll your own from scratch, since progress bars are rather simple.

你也可以从头开始自己动手,因为进度条很简单。