ListBox列表框
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string[] list = { "爱你一万年", "真的爱你", "晚秋", "十年" };
listBox1.Items.AddRange(list);
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
comboBox1.SelectedItem.ToString();
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
MessageBox.Show("当前播放的歌曲为:"+listBox1.SelectedItem.ToString());
}
}
ComboBox下拉列表框
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
comboBox1.Items.AddRange(new string [] { "河南" ,"河北" });
comboBox1.SelectedIndex = 0;
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
//清空市下拉框内的所有选项
comboBox2.Items.Clear();
//如果省份下拉框选择的省份Index为0
if (comboBox1.SelectedIndex==0)
{
comboBox2.Items.AddRange(new string[] { "郑州","开封","许昌"} );
comboBox2.SelectedIndex = 0;
}
if (comboBox1.SelectedIndex == 1)
{
comboBox2.Items.AddRange(new string[] { "石家庄", "邢台", "唐山" });
comboBox2.SelectedIndex = 0;
}
}
}
TreeView树视图控件
private void Form3_Load(object sender, EventArgs e)
{
TreeNode node0 = treeView1.Nodes.Add("新兵峰培训");
//添加一级目录
TreeNode node1 = new TreeNode(".net培训");
TreeNode node2 = new TreeNode("UI培训");
node0.Nodes.AddRange(new TreeNode[2] {node1,node2 });
//添加二级目录
TreeNode node3 = new TreeNode(".net一班");
TreeNode node4 = new TreeNode(".net二班");
TreeNode node5 = new TreeNode(".net三班");
node1.Nodes.AddRange(new TreeNode[3] {node3,node4,node5});
//添加二级目录
TreeNode node6 = new TreeNode("UI培训一班");
TreeNode node7 = new TreeNode("UI培训二班");
TreeNode node8 = new TreeNode("UI培训三班");
node1.Nodes.AddRange(new TreeNode[3] { node6, node7, node8 });
//展开所有节点
treeView1.ExpandAll();
}
ProgressBar进度条控件
private void Form4_Load(object sender, EventArgs e)
{
prBlood.Minimum = 0;
prBlood.Maximum = 100;
}
private void button1_Click(object sender, EventArgs e)
{
if (prBlood.Value < prBlood.Maximum)
{
prBlood.Value += 5;
}
else
{
MessageBox.Show("血已加满!");
}
}
private void button2_Click(object sender, EventArgs e)
{
if (prBlood.Value > prBlood.Minimum)
{
prBlood.Value -= 5;
}
else
{
MessageBox.Show("英雄已死!");
}
}