Jeff Key

It works on my machine

Sponsors

My Job

My stuff

Old stuff

Useful Stuff

EnableVisualStyles: Part of Evil Axis?

[Note:  A nice guy emailed to thank me for the following, which I posted to my .NET list in May but forgot to put on the blog, so I'm posting it now; hopefully it will be useful to someone else.]

If you're using v1.1 of the Framework and encounter an SEHException and
have no idea what's causing it, check to see if you called
Application.EnableVisualStyles().  Apparently that is the source for a
number of problems that appear as SEHExceptions.

My problem in particular was happening when I tried to show a form with
ShowDialog().  If I used Show() instead, no problems.  All of my other
forms had no problems with ShowDialog, yet this one would crash the app.
After a bit of Googling, it appears that this error can come up almost
anywhere, so keep this in mind as it's almost always the solution.
Interestingly, using a manifest file to get the same results does NOT
cause the app to crash.  Go figure.

Comments

Michelle said:

Well, my problem is that every 5 times I run my app, one of them my icons doens´t show up at all, ANY icon, in my treevie, toolbar and even property grid.
I dont want to use a manifest cause I would have to do it every time I compile it.
:S
# August 7, 2003 10:21 AM

Jeff Key said:

So that happens _every_ five times? Haven't heard of that one. Ouch. If you can find a way to add a manifest to the bits via the command line, you could create a post-build event to do it.
# August 7, 2003 10:31 AM

Michelle said:

hehe sorry, language problems here.
I was trying to say that this happens a lot, at least _one_ time every five times I run it.
I mean, its very frequent.

And I'm almost giving up EnableVisualStyles. *sigh*
# August 8, 2003 8:15 AM

Michelle said:

So I gave up using EnableVisualStyles, and I no longer need to add the manifest after every time I compile cause now I puted the correct name on the manifest. Duh.
:)
# August 12, 2003 8:00 AM

Brisemec said:

It seems that calling Application.DoEvents() after calling Application.EnableVisualStyles() fixes some problems.
# October 6, 2003 11:05 AM

Mark Belles said:

Yup, commented that code out, and my app runs like the champ i new it was! I'm gonna do some further testing and pinpoint this, will post back with the results.
# October 30, 2003 9:42 AM

Richard Thompson said:

Thank you. Thank you.

Now I can let my head recover from that stone wall.
# December 29, 2003 1:09 PM

Calis LNb said:

3 days of my life, I have given to EnableVisualStyles and it's cursed progeny, the SEHException. Thank you, Thank you for putting this up on the web where I could see it.
My app ran perfectly for weeks on end after I first put it in place. Only after I reorganized my datasets and made some mods to some mousemove events did the error started coming up 95/100 times . . .
# January 20, 2004 5:11 PM

Donny said:

I got the same SEHException Problem when using ShowDialog() of a form. You have mentioned about "Interestingly, using a manifest file to get the same results does NOT cause the app to crash." Does it mean I can bypass the problem by using a manifest file? Do you have the latest info about the crash problem raised by EnabledVisualStyles?

# June 15, 2004 10:49 PM

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:36 PM

Greg Osborne said:

Does anyone know how to enable visual styles on VS.NET 2003 addins?
# July 15, 2004 12:36 PM