如何仅禁用一个控件的视觉样式,而不是其子控件? [英] How do I disable visual styles for just one control, and not its children?

查看:27
本文介绍了如何仅禁用一个控件的视觉样式,而不是其子控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 替代品 - 这不是我想要的.

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

推荐答案

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

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);
  }
}

这篇关于如何仅禁用一个控件的视觉样式,而不是其子控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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