Windows 98风格的进度条

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

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

你不能轻易获得精确的 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.ocx (版本5)。 我相信第5版是可再发行的,不过版本6我认为不是。 我链接的那个可能不是redist的那个,但那是我测试这些步骤的那个。
第2步:自定义工具箱,然后从“COM组件”选项卡中选择下载的文件(通过浏览)。
第3步:从新工具箱条目添加进度条。

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

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

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