在WinXP环境下显示XP风格的控件
2005-04-14 15:52
405 查看
通过标准的.NET Windows Application我们只能建立一个使用Comctl32.dll Version 5的应用程序。即便我们的程序运行在Windows XP系统下,外观仍旧沿用了Windows 2000。实际上通过简单的设置,就可以让我们的程序在Windows XP下面显示为新的程序外观。
首先我们建立自己的Windows Application,然后拖拽一个按钮(Button),一个进度条(ProgressBar),一个组合框(ComboBox),一个单选框(RadioButton)和一个复选框(CheckBox)。这些控件是在Windows XP下面有其特殊的显示效果。我们把其中的FlatStyle属性设置为System。这个操作表示我们这些控件的平面外观样式使用操作系统的默认值。
之后我们在我们应用程序的文件目录建立一个manifest文件。假如我们的应用程序AssemblyName是myapp,那么这个文件名就是myapp.exe.manifest。编辑这个文件的内容。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
version="1.0.0.0"
processorArchitecture="X86"
name="Microsoft.Winweb.[AssemblyName]"
type="win32"
/>
<description>.NET control deployment tool</description>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="X86"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</assembly>
其中name="Microsoft.Winweb.[AssemblyName]"的部分写入自己程序的AssemblyName。比如这个程序我们就写成name="Microsoft.Winweb.myapp"。保持执行文件和这个manifest文件在同一目录下。这样,如果我们的程序在Windows XP系统下面运行,那么就会自动显示Windows XP的效果。
程序代码如下:
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents CheckBox1 As System.Windows.Forms.CheckBox
Friend WithEvents RadioButton1 As System.Windows.Forms.RadioButton
Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox
Friend WithEvents HScrollBar1 As System.Windows.Forms.HScrollBar
Friend WithEvents VScrollBar1 As System.Windows.Forms.VScrollBar
Friend WithEvents ToolBar1 As System.Windows.Forms.ToolBar
Friend WithEvents ToolBarButton1 As System.Windows.Forms.ToolBarButton
Friend WithEvents ToolBarButton2 As System.Windows.Forms.ToolBarButton
Friend WithEvents ToolBarButton3 As System.Windows.Forms.ToolBarButton
Friend WithEvents StatusBar1 As System.Windows.Forms.StatusBar
Friend WithEvents ProgressBar1 As System.Windows.Forms.ProgressBar
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.CheckBox1 = New System.Windows.Forms.CheckBox
Me.RadioButton1 = New System.Windows.Forms.RadioButton
Me.ComboBox1 = New System.Windows.Forms.ComboBox
Me.HScrollBar1 = New System.Windows.Forms.HScrollBar
Me.VScrollBar1 = New System.Windows.Forms.VScrollBar
Me.ToolBar1 = New System.Windows.Forms.ToolBar
Me.ToolBarButton1 = New System.Windows.Forms.ToolBarButton
Me.ToolBarButton2 = New System.Windows.Forms.ToolBarButton
Me.ToolBarButton3 = New System.Windows.Forms.ToolBarButton
Me.StatusBar1 = New System.Windows.Forms.StatusBar
Me.ProgressBar1 = New System.Windows.Forms.ProgressBar
Me.SuspendLayout()
'
'Button1
'
Me.Button1.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.Button1.Location = New System.Drawing.Point(32, 144)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
'
'CheckBox1
'
Me.CheckBox1.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.CheckBox1.Location = New System.Drawing.Point(40, 200)
Me.CheckBox1.Name = "CheckBox1"
Me.CheckBox1.TabIndex = 1
Me.CheckBox1.Text = "CheckBox1"
'
'RadioButton1
'
Me.RadioButton1.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.RadioButton1.Location = New System.Drawing.Point(152, 200)
Me.RadioButton1.Name = "RadioButton1"
Me.RadioButton1.TabIndex = 2
Me.RadioButton1.Text = "RadioButton1"
'
'ComboBox1
'
Me.ComboBox1.Location = New System.Drawing.Point(144, 152)
Me.ComboBox1.Name = "ComboBox1"
Me.ComboBox1.Size = New System.Drawing.Size(121, 20)
Me.ComboBox1.TabIndex = 3
Me.ComboBox1.Text = "ComboBox1"
'
'HScrollBar1
'
Me.HScrollBar1.Location = New System.Drawing.Point(160, 120)
Me.HScrollBar1.Name = "HScrollBar1"
Me.HScrollBar1.TabIndex = 4
'
'VScrollBar1
'
Me.VScrollBar1.Location = New System.Drawing.Point(256, 48)
Me.VScrollBar1.Name = "VScrollBar1"
Me.VScrollBar1.TabIndex = 5
'
'ToolBar1
'
Me.ToolBar1.Buttons.AddRange(New System.Windows.Forms.ToolBarButton() {Me.ToolBarButton1, Me.ToolBarButton2, Me.ToolBarButton3})
Me.ToolBar1.DropDownArrows = True
Me.ToolBar1.Location = New System.Drawing.Point(0, 0)
Me.ToolBar1.Name = "ToolBar1"
Me.ToolBar1.ShowToolTips = True
Me.ToolBar1.Size = New System.Drawing.Size(292, 28)
Me.ToolBar1.TabIndex = 6
'
'StatusBar1
'
Me.StatusBar1.Location = New System.Drawing.Point(0, 251)
Me.StatusBar1.Name = "StatusBar1"
Me.StatusBar1.Size = New System.Drawing.Size(292, 22)
Me.StatusBar1.TabIndex = 7
Me.StatusBar1.Text = "StatusBar1"
'
'ProgressBar1
'
Me.ProgressBar1.Location = New System.Drawing.Point(24, 64)
Me.ProgressBar1.Name = "ProgressBar1"
Me.ProgressBar1.TabIndex = 8
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 12)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.ProgressBar1)
Me.Controls.Add(Me.StatusBar1)
Me.Controls.Add(Me.ToolBar1)
Me.Controls.Add(Me.VScrollBar1)
Me.Controls.Add(Me.HScrollBar1)
Me.Controls.Add(Me.ComboBox1)
Me.Controls.Add(Me.RadioButton1)
Me.Controls.Add(Me.CheckBox1)
Me.Controls.Add(Me.Button1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
End Class
Mainfest文件如下:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
version="1.0.0.0"
processorArchitecture="X86"
name="Microsoft.Winweb.WindowsApplication1"
type="win32"
/>
<description>.NET control deployment tool</description>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="X86"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</assembly>
首先我们建立自己的Windows Application,然后拖拽一个按钮(Button),一个进度条(ProgressBar),一个组合框(ComboBox),一个单选框(RadioButton)和一个复选框(CheckBox)。这些控件是在Windows XP下面有其特殊的显示效果。我们把其中的FlatStyle属性设置为System。这个操作表示我们这些控件的平面外观样式使用操作系统的默认值。
之后我们在我们应用程序的文件目录建立一个manifest文件。假如我们的应用程序AssemblyName是myapp,那么这个文件名就是myapp.exe.manifest。编辑这个文件的内容。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
version="1.0.0.0"
processorArchitecture="X86"
name="Microsoft.Winweb.[AssemblyName]"
type="win32"
/>
<description>.NET control deployment tool</description>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="X86"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</assembly>
其中name="Microsoft.Winweb.[AssemblyName]"的部分写入自己程序的AssemblyName。比如这个程序我们就写成name="Microsoft.Winweb.myapp"。保持执行文件和这个manifest文件在同一目录下。这样,如果我们的程序在Windows XP系统下面运行,那么就会自动显示Windows XP的效果。
程序代码如下:
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents CheckBox1 As System.Windows.Forms.CheckBox
Friend WithEvents RadioButton1 As System.Windows.Forms.RadioButton
Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox
Friend WithEvents HScrollBar1 As System.Windows.Forms.HScrollBar
Friend WithEvents VScrollBar1 As System.Windows.Forms.VScrollBar
Friend WithEvents ToolBar1 As System.Windows.Forms.ToolBar
Friend WithEvents ToolBarButton1 As System.Windows.Forms.ToolBarButton
Friend WithEvents ToolBarButton2 As System.Windows.Forms.ToolBarButton
Friend WithEvents ToolBarButton3 As System.Windows.Forms.ToolBarButton
Friend WithEvents StatusBar1 As System.Windows.Forms.StatusBar
Friend WithEvents ProgressBar1 As System.Windows.Forms.ProgressBar
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.CheckBox1 = New System.Windows.Forms.CheckBox
Me.RadioButton1 = New System.Windows.Forms.RadioButton
Me.ComboBox1 = New System.Windows.Forms.ComboBox
Me.HScrollBar1 = New System.Windows.Forms.HScrollBar
Me.VScrollBar1 = New System.Windows.Forms.VScrollBar
Me.ToolBar1 = New System.Windows.Forms.ToolBar
Me.ToolBarButton1 = New System.Windows.Forms.ToolBarButton
Me.ToolBarButton2 = New System.Windows.Forms.ToolBarButton
Me.ToolBarButton3 = New System.Windows.Forms.ToolBarButton
Me.StatusBar1 = New System.Windows.Forms.StatusBar
Me.ProgressBar1 = New System.Windows.Forms.ProgressBar
Me.SuspendLayout()
'
'Button1
'
Me.Button1.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.Button1.Location = New System.Drawing.Point(32, 144)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
'
'CheckBox1
'
Me.CheckBox1.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.CheckBox1.Location = New System.Drawing.Point(40, 200)
Me.CheckBox1.Name = "CheckBox1"
Me.CheckBox1.TabIndex = 1
Me.CheckBox1.Text = "CheckBox1"
'
'RadioButton1
'
Me.RadioButton1.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.RadioButton1.Location = New System.Drawing.Point(152, 200)
Me.RadioButton1.Name = "RadioButton1"
Me.RadioButton1.TabIndex = 2
Me.RadioButton1.Text = "RadioButton1"
'
'ComboBox1
'
Me.ComboBox1.Location = New System.Drawing.Point(144, 152)
Me.ComboBox1.Name = "ComboBox1"
Me.ComboBox1.Size = New System.Drawing.Size(121, 20)
Me.ComboBox1.TabIndex = 3
Me.ComboBox1.Text = "ComboBox1"
'
'HScrollBar1
'
Me.HScrollBar1.Location = New System.Drawing.Point(160, 120)
Me.HScrollBar1.Name = "HScrollBar1"
Me.HScrollBar1.TabIndex = 4
'
'VScrollBar1
'
Me.VScrollBar1.Location = New System.Drawing.Point(256, 48)
Me.VScrollBar1.Name = "VScrollBar1"
Me.VScrollBar1.TabIndex = 5
'
'ToolBar1
'
Me.ToolBar1.Buttons.AddRange(New System.Windows.Forms.ToolBarButton() {Me.ToolBarButton1, Me.ToolBarButton2, Me.ToolBarButton3})
Me.ToolBar1.DropDownArrows = True
Me.ToolBar1.Location = New System.Drawing.Point(0, 0)
Me.ToolBar1.Name = "ToolBar1"
Me.ToolBar1.ShowToolTips = True
Me.ToolBar1.Size = New System.Drawing.Size(292, 28)
Me.ToolBar1.TabIndex = 6
'
'StatusBar1
'
Me.StatusBar1.Location = New System.Drawing.Point(0, 251)
Me.StatusBar1.Name = "StatusBar1"
Me.StatusBar1.Size = New System.Drawing.Size(292, 22)
Me.StatusBar1.TabIndex = 7
Me.StatusBar1.Text = "StatusBar1"
'
'ProgressBar1
'
Me.ProgressBar1.Location = New System.Drawing.Point(24, 64)
Me.ProgressBar1.Name = "ProgressBar1"
Me.ProgressBar1.TabIndex = 8
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 12)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.ProgressBar1)
Me.Controls.Add(Me.StatusBar1)
Me.Controls.Add(Me.ToolBar1)
Me.Controls.Add(Me.VScrollBar1)
Me.Controls.Add(Me.HScrollBar1)
Me.Controls.Add(Me.ComboBox1)
Me.Controls.Add(Me.RadioButton1)
Me.Controls.Add(Me.CheckBox1)
Me.Controls.Add(Me.Button1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
End Class
Mainfest文件如下:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
version="1.0.0.0"
processorArchitecture="X86"
name="Microsoft.Winweb.WindowsApplication1"
type="win32"
/>
<description>.NET control deployment tool</description>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="X86"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</assembly>
相关文章推荐
- 为WinXP系统下的MFC控件提供XP的风格样式(部分转载,忘记出处了)
- 让VC6.0写出来的程序在WinXP下显示为XP风格
- vs 2005/2008/2010 ATL ActiveX控件显示XP风格
- vs 2005/2008/2010 ATL ActiveX控件显示XP风格
- 用VB实现带图片的XP风格的按钮控件
- c# 中实现 winxp 风格的控件(超简单-zz)
- vc MFC下让按钮等控件具有XP风格
- [转]在vc MFC下制作具有XP风格按钮等控件
- (转)在DELPHI7中不使用任何第三方控件,实现放在工具栏上可拖动的XP风格菜单
- XP环境在VC6.0下使程序直接具有XP风格(XP style)
- 【Visual Studio风格开发系列 - PropertyGrid控件】PropertyGrid控件中添加自定义显示方式
- vc MFC下让按钮等控件具有XP风格
- 在.NET中使按钮显示为XP风格设置
- WebPanelBar ASP.NET控件,制作动态XP风格菜单的ASP.NET控
- 用户控件--(XP风格的按钮)
- 在 .NET 程序的窗体中使用 XP 风格的控件
- VC实现XP风格控件效果(转)
- 在.NET程序的窗体中使用XP风格的控件
- 解决带清单文件(manifest)C程序移植到XP时无法显示控件的问题
- VC6实现XP风格的控件效果(和VC2005一样)