110,499
社区成员
发帖
与我相关
我的任务
分享
Form2中先定义一个delegate
public delegate void returnvalue( int i );
public returnvalue ReturnValue;
form2 中的button按钮代码如下:
private void button1_Click(object sender, System.EventArgs e)
{
if ( ReturnValue != null )
ReturnValue( 8 );
}
Form1中的button按键如下:
private void button1_Click(object sender, System.EventArgs e)
{
Form2 temp = new Form2( );
temp.ReturnValue = new temp.Form2.returnvalue( showvalue );
temp.Show();
}
private void showvalue( int i )
{
textBox1.Text = i.ToString();
}
点击form2的button,form1中的textbox中的值就会相应变化。
//Main
private void btn_Click(object sender, EventArgs e)
{
frmEx myForm = new frmEx(7);//传参
myForm.Show();
}
//被调用的窗体
int count = 0;
public frmEx()
{
InitializeComponent();
}
public frmEx(int i)
{
InitializeComponent();
count = i;
this.txtLetter.Text = count.ToString();
}