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

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

问题描述

我有一个TabControl的内TabControl的。我想外TabControl的显示在左侧的标签。然而,随着视觉样式启用,左对齐的TabControls显示不正确。我可以禁用视觉样式只是外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.

推荐答案

添加一个新类到您的项目并粘贴下面所示的code。建立。从工具箱顶部的新控件到窗体。视觉样式子控件是preserved。

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天全站免登陆