Windows 98风格的进度条

8

我使用的是Windows 7,所以我的进度条都有那种绿色的外观。不过我想要更简单的样式,也许像Windows 98的进度条那样。

有没有简单的方法可以改变进度条的样式,还是我必须手动重新创建它?

4个回答

9

如果不进行大幅度的控件重写,你很难轻松地获得完全相同的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
或者只需使用早期版本的comctl32。虽然我更喜欢您的解决方案;它可能更加健壮。 - Brian
这实际上是一个非常不错的效果,事实上,在Win10上它似乎很好地匹配了ListBox中所选项目的颜色,因此保持了一致的样式。 - Nyerguds

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, "", "");

1

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

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


0

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


我想关闭一个元素,而不是所有的元素。 - Pieter

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接