问题描述
我的Windows窗体应用程序使用以下标准代码行,以便为整个应用程序启用视觉样式(主题)...
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:碰巧我想从DateTimePicker实例中删除主题,因此,如果一般答案为no DateTimePicker然后就足够了。如果解决方案涉及在最低级别上使用控件,则我很乐意使用平台调用。
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.
推荐答案
看起来您可以在控件上使用SetWindowTheme:
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, "", "");
这篇关于您是否可以仅通过单个Windows控件关闭视觉样式/主题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!