如何创建不带标签头一个TabControl的? [英] How do I create a TabControl with no tab headers?

查看:162
本文介绍了如何创建不带标签头一个TabControl的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何做一个标签管理器不显示的标签头?

How do I make a tab manager that doesn't show the tab headers?

这是一个winforms应用程序,并使用标签管理器的目的是这样的显示内容只能通过code被改变。这是很好的菜单,其中各种菜单选项改变屏幕内容。

This is a winforms application, and the purpose of using a tab manager is so the display content can only be changed through code. It's good for menus where various menu options change the screen contents.

推荐答案

隐藏在标准标签的TabControl 是pretty的简单,一旦你知道的伎俩。该标签控件发送一个 TCM_ADJUSTRECT 的消息当需要调整标签的大小,所以我们只需要捕获该消息。 (我敢肯定,这已经被回答过了,但张贴code是比搜索更容易。)

Hiding the tabs on a standard TabControl is pretty simple, once you know the trick. The tab control is sent a TCM_ADJUSTRECT message when it needs to adjust the tab size, so we just need to trap that message. (I'm sure this has been answered before, but posting the code is easier than searching for it.)

添加以下code一类新的项目,重新编译,并使用,而不是 CustomTabControl 类的内置控件:

Add the following code to a new class in your project, recompile, and use the CustomTabControl class instead of the built-in control:

class CustomTabControl : TabControl
{
    private const int TCM_ADJUSTRECT = 0x1328;

    protected override void WndProc(ref Message m)
    {
        // Hide the tab headers at run-time
        if (m.Msg == TCM_ADJUSTRECT && !DesignMode)
        {
            m.Result = (IntPtr)1;
            return;
        }

        // call the base class implementation
        base.WndProc(ref m);
    }
}

(code样品最初取自点网思想。)

请注意,这将适当的定位在侧面或底部的标签头无法正常工作。但是,不仅只是看起来很怪异,你将无法看到的选项卡在运行时反正。只要把它们放在它们所属的顶部。

Note that this will not work properly for tab headers positioned on the sides or the bottom. But not only does that just look weird, you won't be able to see the tabs at run-time anyway. Just put them on the top where they belong.

这篇关于如何创建不带标签头一个TabControl的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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