Hide Tab Header of Tab Control

November 7, 2012 by Ben Galluzzo    .NET, C#, WinForm |    Comments (0)

There are multiple ways in which the tab header of a tab control can be hidden.  One way is to set the DrawMode of the control to "OwnerDrawFixed," the SizeMode to "Fixed, " and then set the ItemSize to "0, 1"  What's left is somewhat of an abandoned tab header.  A little bit of fussing with the layout is then required to clean up the tab control.  

Another method is to extend the WinForm tab control and override the WndProc method to trap the TCM_ADJUSTRECT message, which is sent when it needs to adjust the size of the tabs, while the control is in DesignMode.  This allows for a nice way of completely eliminating the tab header from the control without any need to clean up the layout.  Once you trap the TCM_ADJUSTRECT message, return the value 1 to specify that the message was handled.

        if (_message.Msg == TCM_ADJUSTRECT && !DesignMode)
            _message.Result = (IntPtr)1;

 

While you're at it, put the class inside your custom library and add it the Visual Studio Toolbox so it can dragged onto a form whenever it is needed. 

using System;

using System.Windows.Forms;

namespace StoreLib
{
    public class NoHeaderTabControl : TabControl
    {
        private const int TCM_ADJUSTRECT = 0x1328;

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

 

References

Control.WndProc Method
TCM_ADJUSTRECT message (Windows)

Add comment




  Country flag
biuquote
  • Comment
  • Preview
Loading







SQL Saturday - 506 - Baltimore BI Edition

Month List