新建一個windows窗體 Form2 ,Form2里也有一個按鈕和一個TextBox控件,在TextBox里輸入你想要的返回值。
Form1里:
~~~
private void button1_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.ShowDialog();
if (f2.DialogResult == DialogResult.OK)
{
this.textBox1.Text = f2.str;
}
}
~~~
Form2里:
~~~
public string str;
public string Str
{
get { return this.str; }
}
private void button1_Click(object sender, EventArgs e)
{
str = this.textBox1.Text;
this.DialogResult = DialogResult.OK;
}
~~~
這種是傳值后Form2關閉的,還有一種是傳值后Form2不關閉的。