Windows Forms: XP Theme Support
Demonstrates how to enables support for XP themes in your application.
Featured Highlights:
To enable XP theme support in your application you have to write very little
code. The main task is to create a manifest file and associate it with your
application.
At this point controls that support XP Themes will appear "themed" in your
application.
This application displays three tabs that highlight the following:
Controls that support Visual Themes without any changes to property settings
Three controls that support visual styles but which are not
demonstrated on this form are H ScrollBar and
V ScrollBar, and the TrackBar control.
Controls that require the flatStyle property to be set to system.
Certain controls that do not support themes or that have limited support are
also demonstrated.
Requirements:
Microsoft Visual Studio.NET Professional or greater.
Windows XP Home or Professional
Running the Sample:
Simply press F5.
Note: The application contains only static data and controls as the only
purpose of this sample is to demonstrate the use of Themes.
If you want to create your own Windows Forms application here are the steps
you will have to perform:
Set each control with a FlatStyle property to FlatStyle.Syste m
Create a manifest file to bind your app to comctl6. The sample manifest file
below can be used to bind any app (managed or unmanaged) to comctl6. Just
copy it to the location of the .exe and rename it to <app
name>.exe.manif est.
You must then add a Win32 resource to your application. This is
accomplished by first opening up the *.exe.
1. Open your exe in VS (file -> open file)
2. Right click on it and select add resource
3. Click "Import..." from the dialog
4. Select your manifest file
5. In the "Resource Type" field, enter "RT_MANIFES T"
6. In the property grid, change the resource ID from "101" to "1".
7. Save the exe.
8. Make sure the manifest is keep at the same directory level as the
executable. (In this How-To it is placed in the bin directory of the
solution)
A sample manifest is also included and is named Sample_Manifest .xml.
Here is the Manifest
Cut-------------------------------------------------------------------------
------------------------------------------------
<?xml version="1.0" encoding="UTF-8" standalone="yes " ?>
<assembly xmlns="urn:sche mas-microsoft-com:asm.v1" manifestVersion ="1.0">
<assemblyIdenti ty version="1.0.0. 0" processorArchit ecture="X86" name="Your
App name here" type
="win32" />
<description>.N ET control deployment tool</description>
<dependency>
<dependentAssem bly>
<assemblyIdenti ty type="win32" name="Microsoft .Windows.Common-Controls"
version="6.0.0. 0"
processorArchit ecture="X86" publicKeyToken= "6595b64144ccf1 df" language="*"
/>
</dependentAssemb ly>
</dependency>
</assembly>
End
cut-------------------------------------------------------------------------
--------------------------------------------
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:uN******** ******@TK2MSFTN GP10.phx.gbl...
"Terry Olsen" <to******@hotma il.com> schrieb:I paste the following code into each project to get XP theme support.
'Add this at the beginning of any program to enable Windows XP Visual
Styles
<System.STAThre ad()> Public Shared Sub Main()
If OSFeature.Featu re.IsPresent(OS Feature.Themes) Then
System.Windows. Forms.Applicati on.EnableVisual Styles()
End If
Application.DoE vents() 'This must be here, otherwise buttons won't
stylize
System.Windows. Forms.Applicati on.Run(New Form1)
End Sub 'Main
Is there a way I can set up the VS IDE to automatically put this code in
each form's code?
You can put the code in your app's main class and don't need it in every
form.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>