仅针对单个表单禁用/关闭视觉样式/主题 [英] Disable/turn off visual styles/theming for just a single form

查看:25
本文介绍了仅针对单个表单禁用/关闭视觉样式/主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 winforms 应用程序.主表单有一些按钮,点击即可打开其他表单.

I have a winforms application. Main form has some buttons that open other forms on click.

有一个表单我想禁用视觉样式/主题.我也想禁用它的孩子的视觉样式.是否可以?如果是这样怎么办?

There is a form I would like to disable visual styles/theme. Also I would like to disable visual styles for its childs. Is it possible? If so how?

例如,假设我在主窗体上有三个按钮:

For example, suppose I have three buttons on main form:

  • Button1 在点击时打开 form1
  • Button2 在点击时打开 form2
  • Button3 在点击时打开 form3
  • Button1 opens form1 on click
  • Button2 opens form2 on click
  • Button3 opens form3 on click

因此,当我单击 Button2 时,我只想禁用其上的视觉样式,但我希望为表单启用视觉样式:form1form3.

so when I click Button2 I would like to only disable visual styles on it but I would like to keep visual styles enabled for forms: form1 and form3.

推荐答案

您可以使用 PInvoke SetWindowTheme:

[DllImport("uxtheme.dll")]
private static extern int SetWindowTheme(IntPtr hWnd, string appname, string idlist);

然后例如在您的 button2 事件处理程序中:

Then for example in your button2 event handler:

var form2 = new Form2();
SetWindowTheme(form2.Handle, "", "");
form2.Show();

这篇关于仅针对单个表单禁用/关闭视觉样式/主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆