如何创建没有选项卡标题的 TabControl?

How do I create a TabControl with no tab headers?(如何创建没有选项卡标题的 TabControl?)
本文介绍了如何创建没有选项卡标题的 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Custom Error Queue Name when using EasyNetQ for RabbitMQ?(使用 EasyNetQ for RabbitMQ 时自定义错误队列名称?)
How to generate password_hash for RabbitMQ Management HTTP API(如何为 RabbitMQ 管理 HTTP API 生成密码哈希)
Rabbitmq Ack or Nack, leaving messages on the queue(Rabbitmq Ack 或 Nack,将消息留在队列中)
Wait for a single RabbitMQ message with a timeout(等待一条带有超时的 RabbitMQ 消息)
Setup RabbitMQ consumer in ASP.NET Core application(在 ASP.NET Core 应用程序中设置 RabbitMQ 消费者)
Specify Publish timeouts in mass transit(指定公共交通中的发布超时)