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

Sim*_*mon 6 .net c# tabcontrol winforms

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

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

Han*_*ant 22

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

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);
  }
}
Run Code Online (Sandbox Code Playgroud)