Friday, December 26, 2003

While playing around with Window forms, I was disappointed to discover that there was no inbuilt mechanism for using Windows XP visual styles for controls - only the title bar appears XP style without any work needed. The actual process of using visual styles, however, is not that complicated.

What is needed is a manifest file placed in the bin directory of your project. The filename should be of the form ApplicationName.exe.manifest where ApplicationName is the name of your application. The actual contents of the manifest file should be like this:
<?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="ApplicationName"
type="win32"
/>
<description>A nice program that behaves properly</description>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="X86"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</assembly>


You can change the "name" attribute to the name of the program.

Finally, some controls have a FlatStyle property; for these controls, this needs to be set to "System".

Recompile and watch the glory of XP visual styles. Unless you're not running XP. In which case you're a very silly person.

No comments: