C#窗体传递参数
来源:百度知道 编辑:UC知道 时间:2024/06/01 08:22:12
3Q啊 在线等=,=
简单,给Form3加两个属性就行了
//在Form1与Form3中定义:
private int _intValA;
private int _intValB;
public int IntValA
{
get{return this._intValA;}
set{this._intValA = value;}
}
public int IntValB
{
get{return this._intValB;}
set{this._intValB = value;}
}
//在Form1中调用Form2
Form2 form2 = new Form2();
bool diaResult = form2.ShowDialog();
//在Form1中调用Form3
Form3 form3 = new Form3();
if(diaResult == DialogResult.OK)
{
form3.IntValA = this._intValA;
form3.IntValB = this._intValB;
}
form3.Show();
//在Form2中:
//假设你这里有一个确认按钮,该按钮的作用是提交你的参数设置
private void Button1_Click(object sender, EventArgs e)
{
Form1 form1 = new Form1();
form1.IntValA = 100;
form1.IntValB = 200;
this.DialogResult = OK;
}
//窗口关闭事件中
private void Form1_Closed(object sender, EventArgs e)
{
this.DialogResult = None;
}
给人写一个两个窗体之间值的