第一个Form,Form1:
string value = string.Empty; using (Form2 frm = new Form2()) { if (frm.ShowDialog() == DialogResult.OK) { //value就是Form2关闭的时候传出的 value = frm.OutValue; } } MessageBox.Show(value);
第二个Form2:
public partial class Form2 : Form { public Form2() { InitializeComponent(); } private void Form2_Load(object sender, EventArgs e) { } public string OutValue; protected override void OnClosing(CancelEventArgs e) { base.OnClosing(e); this.OutValue = "value"; } private void button1_Click(object sender, EventArgs e) { this.DialogResult=DialogResult.OK; this.Close(); } }