Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# : how to remove tabcontrol border?

Tags:

c#

forms

In my form, I'm using a tabcontrol. I want to hide the tab headers and border both. I can do either one, if I try to hide the headers then the border becomes visible. Can anyone help me, please? thanks and here's my code:

public Form3()
{
    InitializeComponent();
    this.NativeTabControl1 = new NativeTabControl();

    this.NativeTabControl1.AssignHandle(this.tabControl1.Handle);

}

private NativeTabControl NativeTabControl1;

private class NativeTabControl : NativeWindow
{
    protected override void WndProc(ref Message m)
    {
        if ((m.Msg == TCM_ADJUSTRECT))
        {
            RECT rc = (RECT)m.GetLParam(typeof(RECT));
            //Adjust these values to suit, dependant upon Appearance
            rc.Left -= 3;
            rc.Right += 3;
            rc.Top -= 3;
            rc.Bottom += 3;
            Marshal.StructureToPtr(rc, m.LParam, true);
        }
        base.WndProc(ref m);
    }

    private const Int32 TCM_FIRST = 0x1300;
    private const Int32 TCM_ADJUSTRECT = (TCM_FIRST + 40);
    private struct RECT
    {
        public Int32 Left;
        public Int32 Top;
        public Int32 Right;
        public Int32 Bottom;
    }

    private void Form3_Load(object sender, EventArgs e)
    {
        //hides tabcontrol headers
        tabControl1.Appearance = TabAppearance.Buttons;
        tabControl1.ItemSize = new Size(0, 1);
        tabControl1.SizeMode = TabSizeMode.Fixed;
    }
}
like image 472
feather Avatar asked Sep 05 '25 17:09

feather


1 Answers

There is another thread on Stackoverflow, which provides some ideas to hide the tab row of the TabControl in Windows Forms.
My favorite one is to override WndProc and set the Multiline property to true.

public partial class TabControlWithoutHeader : TabControl
{
    public TabControlWithoutHeader()
    {
        if (!this.DesignMode) this.Multiline = true;
    }

    protected override void WndProc(ref Message m)
    {
        if (m.Msg == 0x1328 && !this.DesignMode)
            m.Result = new IntPtr(1);
        else
            base.WndProc(ref m);
    }
}

I tested the code on Windows 8.1 and see neither the tabs nor a border line. So I think you do not need to use code like you posted.

like image 134
Koopakiller Avatar answered Sep 07 '25 13:09

Koopakiller