学习Winform分组类控件(Panel、groupBox、TabControl)
分组类控件主要包括容器控件(Panel),分组框控件(groupBox)和选项卡控件(TabControl)等控件。 一、Panel控件 <span style="font-size:18px;"> private void button1_Click(object sender,EventArgs e) { listBox1.Items.Add("子项");//增加子项 listBox1.Height = listBox1.Height + 20;//增加高度 }</span> 完整的窗体代码为: <span style="font-size:18px;">using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApplication3 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender,EventArgs e) { listBox1.Items.Add("子项");//增加子项 listBox1.Height = listBox1.Height + 20;//增加高度 } } } </span> 运行窗体然后多次点击增加按钮的结果为: 二、GroupBox控件 三、TabControl控件 <span style="font-size:18px;"> private void tabControl1_SelectedIndexChanged(object sender,EventArgs e) { MessageBox.Show("你单击了"+tabControl1.SelectedTab.Text //取消单击的选项卡标题 +"它的索引是"+tabControl1.SelectedIndex.ToString());//取消单击的选项卡索引 }</span> 完整的窗体代码为: <span style="font-size:18px;">using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApplication5 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void tabControl1_SelectedIndexChanged(object sender,EventArgs e) { MessageBox.Show("你单击了"+tabControl1.SelectedTab.Text //取消单击的选项卡标题 +"它的索引是"+tabControl1.SelectedIndex.ToString());//取消单击的选项卡索引 } } } </span> 依次单击选项卡的运行结果为: 以上就是本文的全部内容,希望对大家的学习有所帮助。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |