如何创建没有选项卡标题的 TabControl? [英] How do I create a TabControl with no tab headers?

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

问题描述

如何制作不显示选项卡标题的选项卡管理器?

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

这是一个winforms应用程序,使用标签管理器的目的是为了显示内容只能通过代码来改变.它适用于各种菜单选项更改屏幕内容的菜单.

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 上隐藏选项卡非常简单,只要您知道诀窍.向选项卡控件发送 TCM_ADJUSTRECT 消息当它需要调整标签大小时,我们只需要捕获该消息.(我相信这个问题之前已经回答过了,但是发布代码比搜索更容易.)

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.)

将以下代码添加到项目中的新类中,重新编译并使用 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);
    }
}

(代码示例最初取自 Dot Net Thoughts.)

(Code sample originally taken from Dot Net Thoughts.)

请注意,这不适用于位于侧面或底部的标签页眉.但这不仅看起来很奇怪,而且无论如何您都无法在运行时看到选项卡.只需将它们放在它们所属的顶部即可.

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