ProgressBar控件如果其样式为ProgressBarStyle.Marquee则无效果
我正在尝试使用选框样式测试进度条,但没有成功
private void Form1_Load(object sender, EventArgs e)
{
Application.EnableVisualStyles();
this.progressBar1.Style = ProgressBarStyle.Marquee;
this.progressBar1.MarqueeAnimationSpeed = 100;
//this.progressBar1.Value = 0;
}
更新: 在 MSDN 中,
字幕样式仅Windows XP Home Edition、Windows XP Professional x64 Edition、Windows Server 2003 平台支持这是否是问题所在?
更新2: 这似乎是我在我的机器上安装的主题的问题,而不是在 xp 版本上的问题...我删除了主题,问题就消失了!
I am trying to test progress bar with marquee style but with no succeed
private void Form1_Load(object sender, EventArgs e)
{
Application.EnableVisualStyles();
this.progressBar1.Style = ProgressBarStyle.Marquee;
this.progressBar1.MarqueeAnimationSpeed = 100;
//this.progressBar1.Value = 0;
}
Update:
At MSDN
The Marquee style is only supported in Windows XP Home Edition, Windows XP Professional x64 Edition, Windows Server 2003 Platform could this be the problem?
Update2:
It seems the problem with a theme I installed on my machine not on the xp version... I removed the theme and the problem is just gone!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
最有可能的答案可以在文档的摘录中找到:
我猜你在不同的平台上。
Most likely the answer is found in this extract from the documentation:
I guess you are on a different platform.
即使答案已经给出,对于那些可能遇到问题的人来说,进度条的
Maximum
可能设置为 0。在这种情况下,即使使用Style< 也不会出现动画/code> 和
MarqueeAnimationSpeed
设置为正确的值。Even though the answer was already given, for those who may encounter the problem it is possible that the progress bar has
Maximum
set to 0. In that case there will be no animation even withStyle
andMarqueeAnimationSpeed
set to correct values.您应该在创建表单之前调用
EnableVisualStyle
。来自 MSDN:
You should call
EnableVisualStyle
before you create form.From MSDN:
几个答案阅读文档的方式是完全不正确的。事实上,所有版本的 Windows XP 都完全支持选取框样式,包括 32 位 Home 和 Windows 7。 Professional 以及 x64 Edition(与 XP 相比,它与 Windows Server 2003 的共同点确实更多)。您毫无疑问地知道所有这些操作系统都支持该控件的原因是因为它们都包含相同版本的
comctrl32.dll
,它提供了进度条控件的实现。我自己在应用程序中多次使用过这种风格,包括那些在 Windows XP 上运行的应用程序,并且从未遇到过问题。事实上,正如我在评论中提到的,这些版本的操作系统在几个 shell 对话框内部使用这种样式的进度条。
我一直面临着提供代码来证明这种明显回避现象的挑战...我不太确定如何做到这一点,因为问题中显示的代码对我来说效果很好。所以我想我会在这里重新打印它,并附上一些屏幕截图:
在启用 Luna 主题的 Windows XP 下运行:
以及在启用了经典主题的 Windows XP 下运行:
这全部来自干净的虚拟机已加载 Windows XP Professional SP3 32 位。作为证明:
来自演示机的
编辑:如果您安装了自定义主题,则字幕样式可能无法正确显示。检查显示控制面板中的设置。内置 Luna (Windows XP) 和经典主题可以正常工作,非官方的“水彩”主题也是如此。主题设计师负责设计这些元素并将其合并到他们的主题中。如果您发现您的主题不支持此样式,请联系来源以获取更新。
The way that several of the answers are reading the documentation is completely incorrect. In fact, the marquee style is fully supported on all versions of Windows XP, including 32-bit Home & Professional, as well as the x64 Edition (which really has more in common with Windows Server 2003 than XP). The reason that you know without a doubt that all of these operating systems support the control is because they all include the identical version of
comctrl32.dll
, which is what provides the implementation for the progress bar control.I myself have used this style many times in applications, including those that run on Windows XP, and have never had a problem. In fact, as I mentioned in a comment, these versions of the operating system use this style of progress bar internally in several of the shell dialogs.
I've been challenged to provide code that demonstrates this apparently evasive phenomenon... I'm not really sure how to do that, as the code shown in the question works just fine for me. So I guess I'll just reprint that here, along with some screenshots:
Running under Windows XP with the Luna theme enabled:
And running under Windows XP with the Classic theme enabled:
This is all from a clean virtual machine with Windows XP Professional SP3 32-bit loaded. For proof:
Edit: It appears that if you have a custom theme installed, the marquee style may not show up correctly. Check your settings in the Display control panel. The built-in Luna (Windows XP) and Classic themes work correctly, as does the unofficial "Watercolor" theme. Theme designers are responsible for designing these elements and incorporating them into their themes. If you notice that your theme does not support this style, please contact the source for an update.