Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide Tab Header on C# TabControl

I am developing a Windows Form Application with several pages. I am using a TabControl to implement this. Instead of using the header to switch between tabs, I want my application to control this e.g. the next tab should open after the user has filled in a text box and clicked the next button.

like image 519
Hossein Mobasher Avatar asked Aug 05 '11 08:08

Hossein Mobasher


People also ask

How do I hide tabs in tab control?

To hide a tab: tabControl. TabPages. Remove(tabPage);

How do I hide tabs in winform?

To hide a tab in a TabControl, you must remove it from the control's TabPages collection.


3 Answers

Add a new class to your project and paste the code shown below. Compile. Drop the new control from the top of the toolbox onto your form. It shows the tabs at design time so you can easily switch between them while designing. They are hidden at runtime, use the SelectedTab or SelectedIndex property in your code to switch the page.

using System;
using System.Windows.Forms;

public class TablessControl : TabControl {
  protected override void WndProc(ref Message m) {
    // Hide tabs by trapping the TCM_ADJUSTRECT message
    if (m.Msg == 0x1328 && !DesignMode) m.Result = (IntPtr)1;
    else base.WndProc(ref m);
  }
}
like image 174
Hans Passant Avatar answered Nov 01 '22 06:11

Hans Passant


tabControl1.Appearance = TabAppearance.FlatButtons;
tabControl1.ItemSize = new Size(0, 1);
tabControl1.SizeMode = TabSizeMode.Fixed;
like image 31
Geograph Avatar answered Nov 01 '22 04:11

Geograph


Create new UserControl, name it for example TabControlWithoutHeader and change inherited UserControl to TabControl and add some code. Result code should look like:

public partial class TabControlWithoutHeader: TabControl
{
    public TabControlWithoutHeader()
    {
        InitializeComponent();
    }

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

After compile you will have TabControlWithoutHeader control in ToolBox. Drop it on form, in designer you will see headers, but at runtime they'll be hidden. If you want to hide them in designer too, then remove && !DesignMode.

Hope that helps.

http://social.msdn.microsoft.com/Forums/windows/en-US/c290832f-3b84-4200-aa4a-7a5dc4b8b5bb/tabs-in-winform?forum=winforms

like image 17
Renatas M. Avatar answered Nov 01 '22 04:11

Renatas M.