有两种形式form1和form2。单击form12按钮需要在form2上传递一些值作为form2的构造函数参数,而在单击form1的按钮上单击form2则需要显示并使用这些值。
//form1
{
private void btn_Click(object sender, EventArgs e)
{
int a=1;
int b=2;
int c=3;
}
}
//form2
{
private int a=b=c=0;
public Frm2(/*pass parameters here*/)
{
InitializeComponent();
}
}
使用您的问题代码,我试图解决我们的问题:)
// form1
{
private void btn_Click(object sender, EventArgs e)
{
int a=1;
int b=2;
int c=3;
Form2 frm=new Form2(a,b,c);
frm.show();
}
}
//form2
{
private int a=b=c=0;
//it will be main load of your form
public Frm2()
{
InitializeComponent();
}
//pass values to constructor
public Frm2(int a, int b, int c)
{
InitializeComponent();
this.a = a;
this.b = b;
this.c = c;
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句