ProgressBar控件如果其样式为ProgressBarStyle.Marquee则无效果

发布于 2024-11-08 11:49:12 字数 661 浏览 3 评论 0原文

我正在尝试使用选框样式测试进度条,但没有成功

    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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

眼前雾蒙蒙 2024-11-15 11:49:13

最有可能的答案可以在文档的摘录中找到:

Windows XP 家庭版,
Windows XP 专业版 x64
版本,Windows Server 2003
平台注意
:仅这些平台支持 Marquee 样式。

我猜你在不同的平台上。

Most likely the answer is found in this extract from the documentation:

Windows XP Home Edition,
Windows XP Professional x64
Edition, Windows Server 2003
Platform Note
: The Marquee style is supported only on these platforms.

I guess you are on a different platform.

北方的巷 2024-11-15 11:49:13

即使答案已经给出,对于那些可能遇到问题的人来说,进度条的 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 with Style and MarqueeAnimationSpeed set to correct values.

云醉月微眠 2024-11-15 11:49:12

您应该在创建表单之前调用EnableVisualStyle

[STAThread]
static void Main()
{
    Application.EnableVisualStyles();
    Application.Run(new Form1());
}

来自 MSDN

为了达到效果,
必须调用 EnableVisualStyles()
在创建任何控件之前
应用;通常,
EnableVisualStyles() 是第一行
在主函数中

You should call EnableVisualStyle before you create form.

[STAThread]
static void Main()
{
    Application.EnableVisualStyles();
    Application.Run(new Form1());
}

From MSDN:

To have an effect,
EnableVisualStyles() must be called
before creating any controls in the
application; typically,
EnableVisualStyles() is the first line
in the Main function

清旖 2024-11-15 11:49:12

几个答案阅读文档的方式是完全不正确的。事实上,所有版本的 Windows XP 都完全支持选取框样式,包括 32 位 Home 和 Windows 7。 Professional 以及 x64 Edition(与 XP 相比,它与 Windows Server 2003 的共同点确实更多)。您毫无疑问地知道所有这些操作系统都支持该控件的原因是因为它们都包含相同版本的 comctrl32.dll,它提供了进度条控件的实现。

我自己在应用程序中多次使用过这种风格,包括那些在 Windows XP 上运行的应用程序,并且从未遇到过问题。事实上,正如我在评论中提到的,这些版本的操作系统在几个 shell 对话框内部使用这种样式的进度条。

我一直面临着提供代码来证明这种明显回避现象的挑战...我不太确定如何做到这一点,因为问题中显示的代码对我来说效果很好。所以我想我会在这里重新打印它,并附上一些屏幕截图:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        this.progressBar1.Style = ProgressBarStyle.Marquee;
        this.progressBar1.MarqueeAnimationSpeed = 100;
    }
}

在启用 Luna 主题的 Windows XP 下运行:

   在带有 Luna Homestyle 主题的 Windows XP 下运行的跑马灯进度条控件

以及在启用了经典主题的 Windows XP 下运行:

   在带有经典主题的 Windows XP 下运行的字幕进度条控件

这全部来自干净的虚拟机已加载 Windows XP Professional SP3 32 位。作为证明:

来自演示机的 “系统属性”,表明它实际上是 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:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        this.progressBar1.Style = ProgressBarStyle.Marquee;
        this.progressBar1.MarqueeAnimationSpeed = 100;
    }
}

Running under Windows XP with the Luna theme enabled:

   Marquee progress bar control running under Windows XP with the Luna Homestyle theme

And running under Windows XP with the Classic theme enabled:

   Marquee progress bar control running under Windows XP with the Classic theme

This is all from a clean virtual machine with Windows XP Professional SP3 32-bit loaded. For proof:

"System Properties" from the demo machine, indicating that it is, in fact, Windows XP Professional SP3 32-bit

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文