The Artima Developer Community
Sponsored Link

.NET Buzz Forum
Bug with Application.EnableVisualStyles() and image rendering

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Sean McCormack

Posts: 504
Nickname: adapdev
Registered: Jan, 2005

Sean McCormack is the Lead .NET Architect for Miller Brewing Co. and founder of Adapdev Technologies
Bug with Application.EnableVisualStyles() and image rendering Posted: Jun 5, 2005 8:04 PM
Reply to this message Reply

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
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Sean McCormack
Latest Posts From Vini Vidi Vici - Sean McCormack's Blog

Advertisement

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:

        [STAThread]
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.DoEvents();
            ...

Read: Bug with Application.EnableVisualStyles() and image rendering

Topic: POS for .NET Previous Topic   Next Topic Topic: Grown up in public: 2 years of blogging

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use