做了一个列表框的小程序
用鼠标指向列表里的项目 比如 橘子,栗子时
文本框会显示 相应的名字
当你在文本框中输入你想添加的东西
再按一下添加按钮
想添加的东西就会进入列表
当你选中列表框中的莫个item
再按一下移除按钮
相应的item就会移除
按一下清空按钮
列表框所有项目都会消失
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if(listBox1.SelectedIndex!=-1)
textBox1.Text = listBox1.SelectedItem.ToString();
}
private void button1_Click(object sender, EventArgs e)
{
if(textBox1.Text!="")
listBox1.Items.Add(textBox1.Text);
textBox1.Text = "";
}
private void button2_Click(object sender, EventArgs e)
{
if(listBox1.SelectedIndex!=-1)
listBox1.Items.RemoveAt(listBox1.SelectedIndex);
textBox1.Text = "";
}
private void button3_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
}