运行效果:

Winform TabControl控件使用

 

 

 

代码:

 1         /// <summary>
 2         ///  添加选项卡
 3         /// </summary>
 4         /// <param name="sender"></param>
 5         /// <param name="e"></param>
 6         private void button3_Click(object sender, EventArgs e)
 7         {
 8             string tpstring = string.Empty;
 9 
10             if (this.textBox1.Text.Trim() == "")
11             {
12                 MessageBox.Show("不能为空!");
13             }
14             else
15             {
16                 tpstring = this.textBox1.Text.Trim();
17 
18                 TabPage tp = new TabPage(tpstring);
19 
20                 tabControl1.TabPages.Add(tp);
21 
22                 this.textBox1.Text = "";
23             }
24         }
25 
26         /// <summary>
27         /// 删除当前选中选项卡
28         /// </summary>
29         /// <param name="sender"></param>
30         /// <param name="e"></param>
31         private void button1_Click(object sender, EventArgs e)
32         {
33             if (tabControl1.TabPages.Count == 0)
34             {
35                 MessageBox.Show("已经没有可删除的选项!");
36             }
37             else
38             {
39                 tabControl1.TabPages.Remove(tabControl1.SelectedTab);
40             }
41         }

 

 

完成。

 

相关文章:

  • 2022-12-23
  • 2022-01-29
  • 2022-12-23
  • 2021-09-05
  • 2022-02-28
  • 2021-06-02
  • 2022-12-23
猜你喜欢
  • 2021-11-25
  • 2022-12-23
  • 2021-11-26
  • 2022-01-29
  • 2022-12-23
  • 2021-11-11
相关资源
相似解决方案