FAQ: Why do my forms in my managed add-in or VSTO 2003 look Windows 95-ish


This is a frequent question that comes up. You develop a managed add-in or VSTO 2003 code behind.  You show a windows form and yuck–it looks like Windows XP never happened. The buttons aren’t pretty like the Windows XP buttons.  Everything looks circa Windows 95.

The trick is you have to tell Windows Forms to use the Windows XP theming by writing this line of code somewhere in your application before you start creating and showing forms:

System.Windows.Forms.Application.EnableVisualStyles();

That’s it!  Prettiness restored.

Comments (5)

  1. vbNullString says:

    Don’t you have to set FlatStyle to System for TextBox and some other controls?

  2. James McNellis says:

    Yes, for some controls you do have to set the flatstyle to system. Others automatically use the Windows XP styling. Others still never look right (like tab controls…it takes some work to get a gradient background).

    J.

  3. Eric Carter says:

    One other thing I forgot to mention was that in VSTO 2005 we enable visual style for you. So you won’t have to remember to add this line of code in VSTO 2005.

  4. It actually matters *where* you call this method. You must call it before Application.Run and due to timing issues it’s a good idea to call Application.DoEvents between the two calls, like in the following example:

    Application.EnableVisualStyles();

    Application.DoEvents();

    Application.Run(new Form1());

  5. Simon says:

    Also note that there’s a bug in the combobox implementation with visual styles, you’ll get an exception when CLICKING on the scrollbar of a combobox when it’s dropped down.

    Tabs in a tabcontrol cannot be on the left or right of the page too.

    And I’ve bumped into numerous other bugs but I forget where they were.