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.)
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);
}
}
(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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…