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.


  • 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.


  • 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.

  • 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*

  • 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.


  • It seems that calling Application.DoEvents() after calling Application.EnableVisualStyles() fixes some problems.

  • 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.

  • Thank you. Thank you.

    Now I can let my head recover from that stone wall.

  • 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 . . .

  • 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?

  • 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.


    static void Main()


    // Enable XP Theme support(?)



    ClientMainForm clientMainView =

    new ClientMainForm();

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



  • Does anyone know how to enable visual styles on VS.NET 2003 addins?

Comments have been disabled for this content.