Windows 98风格的进度条

时间:2010-10-08 19:17:49

标签: c# winforms progress-bar

我使用的是Windows 7,因此我的进度条都具有绿色外观。我想要一些更简单的东西,或许类似于Windows 98进度条。

是否有一种简单的方法可以更改进度条的样式,还是必须手动重新创建它?

4 个答案:

答案 0 :(得分:7)

如果没有对控件进行非常严格的重写,您将无法轻松获得完全 Win98外观。但是,通过关闭视觉样式可以获得简单的浅蓝色进度条。像这样:

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

class SimpleProgressBar : ProgressBar {
    protected override void OnHandleCreated(EventArgs e) {
        base.OnHandleCreated(e);
        if (Environment.OSVersion.Version.Major >= 6) {
            SetWindowTheme(this.Handle, "", "");
        }
    }
    [DllImport("uxtheme.dll")]
    private static extern int SetWindowTheme(IntPtr hWnd, string appname, string idlist);
}

答案 1 :(得分:1)

第1步:Download COMCTL32.ocx(第5版)。我相信第5版是可再发行的,不过版本6我认为不是。我链接的那个可能不是红色的那个,但那是我测试这些步骤的那个 第2步:自定义工具箱,然后从“COM组件”选项卡中选择下载的文件(通过浏览) 第3步:从新工具箱条目中添加进度条。

注意:在设计器中,它看起来仍然有点像新的进度条。

答案 2 :(得分:1)

我喜欢Hans的答案,但没有必要覆盖控件的类。只需使用控件的句柄调用 SetWindowTheme ,即可从单个控件中删除Win7样式。这是一个例子:

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace MyApplication
{
    public partial class Form1 : Form
    {
        [DllImport("uxtheme", ExactSpelling = true, CharSet = CharSet.Unicode)]
        public extern static Int32 SetWindowTheme(IntPtr hWnd,
                      String textSubAppName, String textSubIdList);

        public Form1()
        {
            InitializeComponent();

            // Remove Win7 formatting from the progress bar.
            SetWindowTheme(progressBar1.Handle, "", "");

答案 3 :(得分:0)

我现在还没有在XP机器上测试过这个...但是我怀疑如果你在应用程序的框架设置下关闭“Windows XP Styles”,你将得到你想要的东西。