int iCount = listBox1.Items.Count; for(int i = 0;i<iCount;i++) { comboBox1.Items.Add(listBox1.Items[i]); }
public class FormA : System.Windows.Forms.Form { public System.Windows.Forms.ListBox listBox1; ......... private void Function() { FormB frm = new FormB(); this.AddOwnedForm(frmB);
for(int i = 0;i<iCount;i++)
{
comboBox1.Items.Add(listBox1.Items[i]);
}
{
public System.Windows.Forms.ListBox listBox1;
.........
private void Function()
{
FormB frm = new FormB();
this.AddOwnedForm(frmB);
frmB.Show();
}
}public class FormB : System.Windows.Forms.Form
{
private Function()
{
object frm = this.Owner;
ListBox lstBox = ((FormA)frm).ListBox1;
int iCount = lstBox.Items.Count;
for(int i = 0;i<iCount;i++)
{
this.comboBox1.Items.Add(lstBox.Items[i]);
}
}
}
WinForm 用 crossbowvic(漫步的兔子) 的就行。
WebForm 就有点儿讨厌,论坛里有相关的问题,你查查看。
可以在窗体B的构造函数里面加传入参数
把窗体A中ListBox的项传到窗体B就可以了