TabControl控件,有时候需要动态显示一个或者多个标签页,如果只是显示一个标签页的时候不想显示标签头,所以有可能隐藏头部的需求。
如下代码可以实现
public Form1() { InitializeComponent(); _tabControlItemSize = tabControl1.ItemSize; _tabControlAppearance = tabControl1.Appearance; _tabSizeMode = tabControl1.SizeMode; } private void showButton_Click(object sender, EventArgs e) { tabControl1.ItemSize = _tabControlItemSize; tabControl1.Appearance = _tabControlAppearance; tabControl1.SizeMode = _tabSizeMode; } private void hideButton_Click(object sender, EventArgs e) { tabControl1.ItemSize = new Size(0, 1); tabControl1.Appearance = TabAppearance.FlatButtons; tabControl1.SizeMode = TabSizeMode.Fixed; } private Size _tabControlItemSize; private TabAppearance _tabControlAppearance; private TabSizeMode _tabSizeMode;// 如果不设置此值,效果是另外一个效果