views:

225

answers:

1

My Windows Forms application uses the following standard line of code so that visual styles (theming) is enabled for the entire application...

Application.EnableVisualStyles();

...which works just fine, all the controls have a themed appearance instead of the flat battleship gray that you would get otherwise. But I need to turn off visual styles for just a single control instance. I cannot remove the above line because then I would lose theming from all the controls. Is it possible to remove theming from a single control instance?

FYI: As it happens I want to remove theming from a DateTimePicker instance so if the general answer is no except for the DateTimePicker then that would be good enough. I am happy to use platform invoke if the solution involves playing with the control at the lowest level.

+1  A: 

It looks like you can use SetWindowTheme on a control:

[DllImport("uxtheme", ExactSpelling = true, CharSet = CharSet.Unicode)]
public extern static Int32 SetWindowTheme (IntPtr hWnd, 
              String textSubAppName, String textSubIdList);

yourControl.FlatStyle = FlatStyle.System;
SetWindowTheme(yourControl.Handle, "", "");

Original CodeProject Article

David Brown