You can set ControlStyles.UserMouse
to true. This way you can simply disable mouse on tab headers.
By the way, just disabling click on headers is not enough and you need to disable keys which let the user to switch to between tabs, like Shift+Tab, Ctrl+Shift+Tab, ←, →, Home and End.
using System.Linq;
using System.Windows.Forms;
using System.ComponentModel;
public class MyTabControl : TabControl
{
public MyTabControl()
{
if (LicenseManager.UsageMode != LicenseUsageMode.Designtime)
SetStyle(ControlStyles.UserMouse, true);
}
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
var filteredKeys = new Keys[]{(Keys.Control | Keys.Tab),
(Keys.Control | Keys.Shift | Keys.Tab),
Keys.Left, Keys.Right, Keys.Home, Keys.End};
if (filteredKeys.Contains(keyData))
return true;
return base.ProcessCmdKey(ref msg, keyData);
}
}
Note: If you like to have a wizard-like control (tab control without header), you can handle TCM_ADJUSTRECT
like this. You should disable those keys also in that solution too. Here is a changed version:
using System.Linq;
using System.Windows.Forms;
using System.ComponentModel;
public class WizardControl: TabControl
{
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
var filteredKeys = new Keys[]{(Keys.Control | Keys.Tab),
(Keys.Control | Keys.Shift | Keys.Tab),
Keys.Left, Keys.Right, Keys.Home, Keys.End};
if (filteredKeys.Contains(keyData))
return true;
return base.ProcessCmdKey(ref msg, keyData);
}
public const int TCM_FIRST = 0x1300;
public const int TCM_ADJUSTRECT = (TCM_FIRST + 40);
protected override void WndProc(ref Message m)
{
if (m.Msg == TCM_ADJUSTRECT && !DesignMode)
m.Result = (IntPtr)1;
else
base.WndProc(ref m);
}
}