No, this doesn't exist. You have to remove the tab and re-add it when you want it. Or use a different (3rd-party) tab control.
使用TabControl中的TabPages属性的方法
public TabControl.TabPageCollection TabPages { get; }
第一个直接移除实例
第二个根据下标移除
第三个根据TabPage的名字来移除
第三个方法中的 key指的是:"The Name property corresponds to the key for a TabPage in the TabControl.TabPageCollection.
public partial class Form1 : Form { private TabControl tabControl; public Form1() { InitializeComponent(); LoadTabControl(); RemoveTabPges("tab"); } private void LoadTabControl() { tabControl = new TabControl { Dock = DockStyle.Fill }; Controls.Add(tabControl); LoadTabPages(); } private void LoadTabPages() { if (tabControl == null) { throw new ArgumentNullException("tabControl", "tabControl can not be null"); } TabPage tabPage; tabPage = new TabPage { Text = "tabPage1",Name = "tab"}; tabControl.TabPages.Add(tabPage); tabPage = new TabPage() { Text = "tabPage2" ,Name = "tab"}; tabControl.TabPages.Add(tabPage); TabControl.TabPageCollection tabPageCollection = tabControl.TabPages; foreach (var item in tabPageCollection) { Console.WriteLine(); } if (tabPageCollection.ContainsKey("tab")) { Console.WriteLine("Exist"); } } private void RemoveTabPges(string key) { try { if (tabControl != null) { tabControl.TabPages.RemoveByKey(key); tabControl.TabPages.RemoveByKey(key); tabControl.TabPages.RemoveByKey(key); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
需要注意的,根据key移除tabPage的时候,如果有重名的tabPage的话。
删除规则,类似于队列,先添加到TabControl的,先被删除
如果找不到匹配的话,也不会报异常