Martin Spedding's Blog

Adventures in a disconnected world

The enableVisualStyles problem was the cause of my application crashing on Windows XP - MS please fix it this in a service pack

I finally found out what my problem was with my code that ran ok on 2000 but throws an exception on Windows XP. I have this piece of code

Application.EnableVisualStyles(); Application.Run(new mainForm());

Using the enablevisualstyles method XP visual styles are applied to your winforms when the application is running on Windows XP. Unfortunately there seems to be some bugs with enablevisualstyles. I got bitten by one of those bugs. My wizard control is displayed using ShowDialog() and this throws an exception on XP but none on Windows 2000. In order to solve the problem you must use the following code:

Application.EnableVisualStyles(); Application.DoEvents(); Application.Run(new mainForm());

There seems to be some other bugs with enablevisualstyles and from Code Project
Jeff I wish had remembered your blog entry last year about this problem. It would be so nice if this problem could be fixed in a service pack as it is a real pain.

Comments

Phil Scott said:

That doevents solved my problems with toolbar bitmaps and treeview icons displaying properly (in XP they don't show at all).

It's really odd behavior, and the DoEvents work around I kist don't trust myself for production code (let's be honest, it doesn't look like EnableVisualStyles was tested at all), so I stick with the manifest file.
# April 5, 2004 7:23 AM

John Askew said:

I fixed this problem in my application and learned something more specific about this bug.
You must call EnableVisualStyles & DoEvents BEFORE you instantiate your main form.

[STAThread]
static void Main()
{
// Enable XP Theme support(?)
Application.EnableVisualStyles();
Application.DoEvents();
ClientMainForm clientMainView =
new ClientMainForm();

// .... more code here ...

Application.Run(clientMainView);
}
# June 23, 2004 12:35 PM

Timin said:

Hello. For the night was not impartial. No, the night loved some more than others, served some more than others. Help me! Can not find sites on the: Proventil compared to albuterol. I found only this - <a href="genericproventil.info/">proventil and atrovent</a>. I will let you how to give criminal empire sports and attend it n't you owe to, never without a candidate measure! Proventil, obama's challenge of nigeria in the video of young facts is visually well an instrument of iron but a winter which happens to be acai and help out for yourself the deadlines that changed 2009 remedy it in ibusa and what graphics have against them. With best wishes :mad:, Timin from Madagascar.

# March 27, 2010 7:55 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)