WinForm TabControl:如何动态隐藏/显示选项卡标题?

new*_*man 3 tabcontrol winforms

我想让tabControl更智能一些,以节省一些屏幕空间:如果只有一个选项卡,则不显示选项卡标题,如果有两个或更多选项卡,则显示选项卡标题.

我知道您可以完全隐藏选项卡标题,如何如何创建没有标签标题的TabControl?.这种方法的问题是,一旦隐藏,我就无法再显示标签页眉.还是我错过了什么?

Han*_*ant 5

相信那个真正提出这个想法的人:

using System;
using System.ComponentModel;
using System.Windows.Forms;

public class WizardPages : TabControl {
    private bool tabsVisible;

    [DefaultValue(false)]
    public bool TabsVisible {
        get { return tabsVisible; }
        set {
            if (tabsVisible == value) return;
            tabsVisible = value;
            RecreateHandle();
        }
    }

    protected override void WndProc(ref Message m) {
        // Hide tabs by trapping the TCM_ADJUSTRECT message
        if (m.Msg == 0x1328) {
            if (!tabsVisible && !DesignMode) {
                m.Result = (IntPtr)1;
                return;
            }
        }
        base.WndProc(ref m);
    }
}
Run Code Online (Sandbox Code Playgroud)