我有 2 个表格 form1 和 form2。当我单击button2时,我想将checkedlistbox1(form1)中的选中项目添加到列表框(form2)。我怎样才能做到这一点
表格1
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
form2.Show();
}
}
表格2
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
Form1 form1 = new Form1();
foreach(string item in form1.checkedListBox1.CheckedItems)
{
listBox1.Items.Add(item);
}
}
}