2

I have a .net WinForms app with buttons that are displaying as XP style (rounded corners) at design time, but Windows 2000 style (square corners) at runtime. My desktop theme is set to XP style. I'm guessing there's an obvious setting that I'm overlooking. Thanks.

3 Answers 3

6

In your Program.Main() method make sure you have these 2 lines before Application.Run:

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
2
static void Main() 
{
    Application.EnableVisualStyles();
    Application.Run(new Form1());
}

EnableVisualStyles must be called before creating any controls in the application; typically, EnableVisualStyles is the first line in the Main function.

MSDN Reference

2

There's also an option in project properties called Enable XP Visual Styles that does the same trick... Actualy if you put the code above, this checkbox will become check in the project properties...

2
  • 1
    Nice tip, although I found that it only applies to VB projects.
    – Jeff Hall
    May 5, 2009 at 19:12
  • Oh well... I tought it was a general properties for projects... The only language where I sometime used this option is VB, with C# I never had to do this to get the XP Style... Weird... May 5, 2009 at 19:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.