views:

20

answers:

2

As shown in this screenshot, windows forms widgets appear different in design mode than they do in the actual runtime.

I'm using VS2008 Pro and my desktop is set to use the default windows-xp style. Why does .net insist on using legacy widgets? My google-foo fails to find a solution that doesn't require custom widgets or extended user controls.

The DropDownStyle and FlatStyle properties are default, but no combination of settings results in runtime widgets looking the same as in design mode.

What might be the cause of this and how can I change the behavior?

+4  A: 

You have to enable visual styles. Try the following in the Main():

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

I seem to remember in .Net 1.1 you could do this with an external manifest, but that stopped working with 2.0.

jbloomer
Many thanks, that worked as expected. Why isn't this the default option? Are there unintended consequences or side effects?
16bytes
I don't have any personal experiences of side effects, but I've only used it on XP and later, not sure why it isn't the default.
jbloomer
+2  A: 

Jbloomer's answer is correct.

I thought it might be helpful to add where I remember learning this: SSW's Rules to Better Windows Forms Applications.

The tips in there are very, very useful.

Josh Kodroff
Great! Thanks for the link. The page mentions that using this may result in an exception being thrown in certain curcumstances. Have you had any problems with it (and possible work-arounds)?
16bytes
I never experienced an exception being thrown with EnableVisualStyles, but don't take that as an authoritative answer as I was working on an internal app so the machines were all on the same version of XP. That said, if it works on SP2 and SP3, you're probably safe.
Josh Kodroff