Can you turn off visual styles/theming for just a single windows control?

回眸只為那壹抹淺笑 提交于 2019-12-20 06:43:15

问题


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:


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



来源:https://stackoverflow.com/questions/544203/can-you-turn-off-visual-styles-theming-for-just-a-single-windows-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!