如何仅为一个控件而不是其子控件禁用视觉样式?

时间:2022-10-30 09:14:23

I have a TabControl within a TabControl. I want the outer TabControl to show its tabs on the left. However, with Visual Styles enabled, left-aligned TabControls don't display properly. Can I disable Visual Styles for just the outer TabControl?

我在TabControl中有一个TabControl。我希望外部TabControl在左侧显示其选项卡。但是,启用视觉样式后,左对齐的TabControls无法正确显示。我可以只为外部TabControl禁用视觉样式吗?

I'm aware of the third-party TabControl replacements - that's not what I'm after.

我知道第三方TabControl替换 - 这不是我想要的。

1 个解决方案

#1


20  

Add a new class to your project and paste the code shown below. Build. Drop the new control from the top of the toolbox onto your form. Visual styles of the child controls are preserved.

在项目中添加一个新类并粘贴下面显示的代码。建立。将新控件从工具箱顶部拖放到表单上。保留子控件的视觉样式。

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

public class FixedTabControl : TabControl {
  [DllImportAttribute("uxtheme.dll")]
  private static extern int SetWindowTheme(IntPtr hWnd, string appname, string idlist);

  protected override void OnHandleCreated(EventArgs e) {
    SetWindowTheme(this.Handle, "", "");
    base.OnHandleCreated(e);
  }
}

#1


20  

Add a new class to your project and paste the code shown below. Build. Drop the new control from the top of the toolbox onto your form. Visual styles of the child controls are preserved.

在项目中添加一个新类并粘贴下面显示的代码。建立。将新控件从工具箱顶部拖放到表单上。保留子控件的视觉样式。

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

public class FixedTabControl : TabControl {
  [DllImportAttribute("uxtheme.dll")]
  private static extern int SetWindowTheme(IntPtr hWnd, string appname, string idlist);

  protected override void OnHandleCreated(EventArgs e) {
    SetWindowTheme(this.Handle, "", "");
    base.OnHandleCreated(e);
  }
}