Using Windows XP Themes

Provided by Dan Haught, FMS Executive Vice President & Scott Ellis, Senior Project Manager

Windows XP introduced an updated, more modern User Interface. With a small amount of work, you can take advantage of the Windows XP visual styles in your applications.

There are three basic steps:

  • Step 1: For every control with a FlatStyle property, set it to FlatStyle.System.
  • Step 2: Create a manifest file to bind your application to Comctl32.dll, version 6.0.
  • Step 3: Include the Manifest file with your project.

Version 1.1 of the .NET Framework introduced a simplified method of incorporating XP themes in your applications by using the Application.EnableVisualStyles method in the application’s entry point:

' VB
Public Shared Sub Main()
    System.Windows.Forms.Application.EnableVisualStyles()
    System.Windows.Forms.Application.Run(New Form1)

End
Sub 

// C#
static void Main()
{
    Application.EnableVisualStyles();
    Application.Run(new Form1());
}

However, this method has been proven unreliable. Some controls may not pick up the theme, and images have been known to disappear from ToolBars, TreeViews, and ListViews. Microsoft suggests calling Application.DoEvents as a workaround, but developers have reported memory leaks and unhandled exceptions using this workaround.

The safest way to ensure your application’s integrity is to stick with the manifest approach.


Step 1: For every control with a FlatStyle property, set it to FlatStyle.System.

Some controls support XP styles with no additional work, however controls that derive from the ButtonBase class (Button, CheckBox, RadioButton) and the GroupBox control must have their FlatStyle property set to System. Setting this property to System lets the operating system determine how the control displays.


Step 2: Create a manifest file to bind your application to Comctl32.dll, version 6.0.

Your application must include a manifest file that tells Windows XP that it supports themes. The easiest way to create this file is to use another application's manifest as a template, or use the template below:

<? xml version ="1.0" encoding ="UCS-2" standalone ="yes"?>
<
assembly xmlns ="urn:schemas-microsoft-com:asm.v1" manifestVersion ="1.0">
<
assemblyIdentity
   
version ="1.0.0.0"
   
processorArchitecture ="X86"
   
name ="MyApplicationName"
   
type ="win32"
/>
<
description >My Application Description </description >
<
dependency >
    < dependentAssembly>
        < assemblyIdentity

           
type ="win32"
           
name ="Microsoft.Windows.Common-Controls"
           
version ="6.0.0.0"
           
processorArchitecture ="X86"
           
publicKeyToken ="6595b64144ccf1df"
           
language ="*"
       
/>
    </dependentAssembly >

</
dependency >
</
assembly >


Step 3: Include the manifest with your project.

To do this, include the manifest as a file and place it in the same directory as your assembly (exe or dll).

The file should be named as follows:

application_name.exe.manifest
or
application_name.dll.manifest

Where application_name is the name of your application. For example, if your application is called Editor.exe, your manifest file name would be:

editor.exe.manifest

Alternatively, you can include your manifest as a resource by following these steps:

  1. Open your project in Visual Studio .NET.
  2. Right-click on your executable file and select "Add Resource."
  3. Click the "Import..." button and point to your resource file on disk.
  4. In the "Resource Type" field, type in "RT_MANIFEST."
  5. In the property grid, change the resource ID from its default of 101 to 1.
  6. Save the executable file.

Additional Resources

 

 

Thank you! Thank you! I just finished reading this document, which was part of a link in the recent Buzz newsletter. I have printed it for others to read, especially those skeptical on the powers of Access and its capabilities.

Darren D.


View all FMS products for Microsoft Access All Our Microsoft Access Products

 

 

Free Product Catalog from FMS