Microsoft KB Archive/303636

= How To Use Windows XP Visual Styles with .NET Windows Forms =

PSS ID Number: 303636

Article Last Modified on 7/15/2004

-

The information in this article applies to:


 * Microsoft Visual Studio .NET (2002), Professional Edition

-



This article was previously published under Q303636



SUMMARY
With Microsoft Windows XP, you can define the visual style or appearance of controls and windows in a variety of ways, from simple colors to textures and shapes. Visual styles are specifications for the appearance of controls. If you want your application to use Windows XP visual styles, you must add an application manifest that indicates that ComCtl32.dll version 6 should be used if it is available. Version 6 includes the support for changing the appearance of controls in a window.

In Visual Studio .NET, you cannot create your own visual styles, however, you can configure your .NET Windows Forms applications to use the visual styles of the controls that are provided by Windows XP.

Many of the .NET Windows Forms controls are merely wrappers for the common controls that are provided by the operating system. However, .NET Windows Forms provides formatting capabilities that are not built into the common controls (for example, a flat Web look to the controls). Therefore, in most cases, the .NET Windows Forms takes on the responsibility of drawing the controls.

To take advantage of the visual styles of the controls, the .NET Windows Forms needs to relinquish the drawing back to the common controls library. You do this by setting a FlatStyle property on the controls and building a manifest file. A manifest file is just an XML file that contains run-time information about the application. It takes control at the application level. Therefore, you need only one manifest to affect the whole application, including any .dll files that the application may use.



MORE INFORMATION
To introduce Windows XP visual styles into your Windows application, follow these steps:  Create a new Windows application and add some controls to the default form. For every control that you put on the form that has a FlatStyle property, set the property to System. Compile the application. Build a manifest file in the application directory.

NOTE: This manifest file must be located in the same directory as the executable.  Open a text editor program (such as Notepad) and paste the following code in a new file:   .NET control deployment tool  <assemblyIdentity type=&quot;win32&quot; name=&quot;Microsoft.Windows.Common-Controls&quot; version=&quot;6.0.0.0&quot; processorArchitecture=&quot;X86&quot; publicKeyToken=&quot;6595b64144ccf1df&quot; language=&quot;*&quot; />       </dependentAssembly> </li> Save the file in the application directory with the name of the application and an extension of exe.manifest. For example, if your application name is MyApp, name the manifest file MyApp.exe.manifest.

When the application runs, Windows XP looks at the application manifest, which tells the operating system to use common controls library version 6.0.</li></ol>

<div class="references_section">