//Form1窗体添加的代码
private void Form1_Load(object sender, EventArgs e)
{
listBox1.Items.Add("0");//添加选项0
listBox1.Items.Add("1");//添加选项1
listBox1.Items.Add("2");//添加选项2
listBox1.Items.Add("3");//添加选项3
listBox1.Items.Add("4");//添加选项4
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
Form2 frm = new Form2(listBox1.SelectedIndex);//显示Form2窗体
frm.Show();
}
//Form2窗体添加的代码
private int index;
public Form2(int index)
{
InitializeComponent();
this.index = index;
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("items 索引值:" + index);
}