Click here to Skip to main content
Click here to Skip to main content

Application.EnableVisualStyles Bug

, 25 Oct 2003
Rate this:
Please Sign up or sign in to vote.
Calling Application.EnableVisualStyles prevents images from an ImageList from appearing on Windows Common Controls


Version 1.1 of the .NET framework introduced the method System.Windows.Forms.Application.EnableVisualStyles. Calling this method prior to the creation of any Forms or Controls, will cause Windows XP to apply a theme when rendering Windows Common Controls and many of the native .NET controls like Buttons and CheckBoxes.

Using .NET 1.0, MFC, WTL or VB6, it is necessary to include a manifest, either in the same directory as the executable, or compiled into it as a resource, in order to make use of Windows XP visual styles. While not overly difficult, providing a manifest for every executable one creates is tedious, and Visual Studio has very little tool support for helping you to do so.

The introduction of EnableVisualStyles to v1.1 of the framework is a nice addition because it allows WinForms applications to easily adopt the new look and feel of Windows XP styles.

The Bug

The problem is that there is bug in the implementation of EnableVisualStyles that interferes with Images stored in an ImageList component and Window Common Controls, like the TreeView or Toolbar classes. The effect is that if you call EnableVisualStyles, all of the images will disappear from your toolbars, treeviews and listviews.

To reproduce the bug:

  1. Create a WinForms application in VS.NET 2003
  2. Add a Toolbar and ImageList to Form1
  3. Add an image to the ImageList and a button to the Toolbar
  4. Assign the image to the button
  5. In the Main method add a call to Application.EnableVisualStyles just before the call to Application.Run

When you run the app on Windows XP, with a Visual Style active, there will be no image on the toolbar button.

Work Around

After some searching through Google groups I found some discussion of this issue and a work around that seems to work and hasn't caused any problems in my applications. (To read more about the work-around go here)

A call to Application.DoEvents just after EnableVisualStyles, seems to fix the problem. How or why, who knows. Most likely it causes some message that was sent via PostMessage to get flushed out to the correct place, before the creation of the first WinForms based window.

So the work around code looks like this:

void Main() 
  Application.Run(new Form1()); 

As of yet, I haven't seen any ill effect from the work-around and it seems to always work.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Don Kackman
Team Leader Starkey Laboratories
United States United States
The first computer program I ever wrote was in BASIC on a TRS-80 Model I and it looked something like:
10 PRINT "Don is cool"
20 GOTO 10
It only went downhill from there.

Hey look, I've got a blog
Follow on   Twitter

Comments and Discussions

GeneralListViewItem's losing BackColor and ForeColor was fixed! PinmemberHideki Oga2-Sep-08 21:43 
GeneralAdditional information PinmemberCrafter772-Nov-07 11:56 
GeneralGracias!! Pinmemberomtzr18-Sep-06 15:08 
GeneralThanks! PinmemberFred Fredburger21-Jul-06 20:45 
GeneralRe: Thanks! PinmemberFred Fredburger21-Jul-06 20:45 
GeneralRe: Thanks! PinmemberFred Fredburger21-Jul-06 20:46 
QuestionNew issue in .NET 2.0 with visual styles... Pinmemberxlouk3-Jul-06 5:51 
AnswerRe: New issue in .NET 2.0 with visual styles... Pinmemberxlouk11-Jul-06 2:22 
GeneralThanks PinmemberBikash Rai13-Dec-05 0:48 
GeneralSimple Button And Imagelist Pinmember.::CenoByte::.28-Jul-05 21:24 
GeneralA Different Solution to Missing Icons PinsussSmittyInPhilly29-Jun-05 5:41 
GeneralRe: A Different Solution to Missing Icons PinmemberBen Shemmeld21-Feb-06 19:29 
JokeRe: A Different Solution to Missing Icons PinmemberBen Shemmeld23-Feb-06 11:10 
GeneralRe: A Different Solution to Missing Icons Pinmembermliddekee20-Mar-06 12:07 
GeneralStill Buggy PinsussAnonymous22-May-05 16:20 
GeneralMonthCalendar bug when using XP Styles Pinmembercmaroto16-May-05 4:55 
GeneralRe: MonthCalendar bug when using XP Styles PinmemberDon Kackman16-May-05 9:11 
GeneralTry this Pinmemberhravn22-Feb-05 8:43 
General' System.Windows.Forms.Application.EnableVisualStyles() Pinmemberspratticus30-Nov-04 17:30 
GeneralWorks PinsussAnonymous3-Nov-04 19:44 
GeneralRe:Enable Visual Styles : solution PinsussAnonymous30-Nov-04 6:40 
GeneralEnableVisualStyles doesn't work Pinmemberafinnell20-Oct-04 13:33 
GeneralRe: EnableVisualStyles doesn't work PinmemberDon Kackman22-Oct-04 9:29 
GeneralRe: EnableVisualStyles doesn't work PinmemberThe_Mega_ZZTer22-Aug-07 6:21 
GeneralDon't be too haisty PinmemberRodgerB16-Aug-04 7:00 
GeneralThanks! PinmemberDaniel Turini2-Jul-04 4:13 
Generaland another bug with combobox PinmemberMrPolite (Kourosh Derakshan)22-Apr-04 22:06 
GeneralBug (?) #3 When using only ShowDialog PinmemberNiels Penneman4-Jan-04 9:41 
GeneralRe: Bug (?) #3 When using only ShowDialog PinmemberDon Kackman4-Jan-04 9:59 
GeneralRe: Bug (?) #3 When using only ShowDialog PinmemberNiels Penneman4-Jan-04 10:35 
GeneralRe: Bug (?) #3 When using only ShowDialog PinmemberDon Kackman4-Jan-04 10:46 
GeneralYou just saved my Life Pinmemberwitzulu6-Dec-03 2:09 
GeneralRe: You just saved my Life PinmemberDon Kackman10-Dec-03 7:09 
GeneralGreat, thanks, it worked! PinmemberLeon v Wyk13-Nov-03 23:31 
GeneralYet Another Bug PinsussHanreG29-Oct-03 20:09 
GeneralRe: Yet Another Bug PinmemberDon Kackman30-Oct-03 14:49 
GeneralRe: Yet Another Bug PinsussHanreG30-Oct-03 19:46 
GeneralRe: Yet Another Bug - Solution 2 PinmemberPreky7-Apr-06 3:16 
GeneralMore info on this bug PinmemberGIngelmo27-Oct-03 5:38 
GeneralYou're right... PinmemberJerry Maguire26-Oct-03 6:43 
GeneralRe: You're right... PinmemberCarl Mercier26-Oct-03 12:19 
GeneralRe: You're right... Pinmemberafs_intel8-Jun-04 12:16 
GeneralRe: You're right... PinmemberChris Voon9-Sep-04 6:35 
GeneralRe: You're right... PinmemberThe Man from U.N.C.L.E.25-Nov-04 4:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150414.1 | Last Updated 26 Oct 2003
Article Copyright 2003 by Don Kackman
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid