This post originated from an RSS feed registered with .NET Buzz
by Sean McCormack.
Original Post: Bug with Application.EnableVisualStyles() and image rendering
Feed Title: Vini Vidi Vici - Sean McCormack's Blog
Feed URL: http://smccormack.blogs.com/adapdev/SyndicationService.asmx/GetRss
Feed Description: Sean McCormack's Blog, focusing on various aspects of .NET development, open source projects, recommended books and tools
So, if you'd like to save yourself the two hours that I wasted trying to figure this
out, then here's my gift to you! :-)
When you call Application.EnableVisualStyles() at the beginning of a windows
app, it will automatically render the app using the Windows XP theme (you have to
be on Windows XP or Windows 2003 for the theme to appear).
Unfortunately, there's a bug in the .NET 1.1 framework. In my case, I had a
TreeView with an ImageList. The images appear when I don't call that method,
but disapper when I do call that method.
After doing a lot of user group searches, it turns out that EnableVisualStyles has
a bug that creates a windows handle before the images can be processed and rendered.
To fix it, all you have to do is call Application.DoEvents() immediately after.
This somehow clears the stack and reapplies everything - to include the images.
According to the posts I read, this bug affects a lot of controls with images, and
this fix should apply for most. Here's some example code: