我使用的是Windows 7,所以我的进度条都有那种绿色的外观。不过我想要更简单的样式,也许像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);
}
我喜欢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:下载 COMCTL32.ocx(版本5)。我相信版本5是可再分发的,尽管我认为版本6不是。我链接的那个可能不是redist版本,但那是我测试这些步骤的版本。
步骤2:自定义工具箱并从“COM组件”选项卡中选择您从中下载的文件(通过浏览它)。
步骤3:从新的工具箱条目中添加一个进度条。
注意:在设计器中,它仍然看起来像一个较新的进度条。
我现在还没有在XP机器上测试过这个...但我怀疑如果你在应用程序的框架设置中关闭“Windows XP样式”,你将得到你想要的效果。