Enable Visual Styles Bug
Enabling the use of Themes in .net apps may cause the following error:
‘System.Runtime.InteropServices.SEHException’ occurred in system.windows.forms.dll
Background information regarding this bug can be obtained at Code Project’s BugList
There are two solutions for this bug:
The first solution is to add Application.DoEvents() just after calling EnableVisualStyles() on the main form:
void Main()
{
Application.EnableVisualStyles();
Application.DoEvents();
Application.Run(new Form1());
}
The second solution is to create an application external manifest file:
Create a new xml file in the application directory with the name of the application and an extension of exe.manifest. For instance, if your application name is "MyApp", you will name the manifest file as MyApp.exe.manifest. Place the following content in this file.
<?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" This is the application version
processorArchitecture="X86"
name="Theme Test" This is the application name
type="win32" /> This is the application description
<description>Testing Windows XP Visual Styles.</description>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="X86"
publicKeyToken="6595b64144ccf1df"
language="*" />
</dependentAssembly>
</dependency>
</assembly>
Its possible to embed this file into the executable as John McTainsh explains in this article.
Some information about this bug can be found at Cool Client Stuff blog