Freigeben über


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

  • Anonymous
    October 22, 2004
    Don't you have to set FlatStyle to System for TextBox and some other controls?
  • Anonymous
    October 22, 2004
    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.
  • Anonymous
    October 22, 2004
    The comment has been removed
  • Anonymous
    October 22, 2004
    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());
  • Anonymous
    October 22, 2004
    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.