Form1傳參數給Form2,在Form2中進行修改以後,再傳回給Form1,Form1視窗中資料改變。
Form1中:
1
public override void addBtn_Click( object sender, System.EventArgs e)
2
{
3
Form2 item = new Form2 ();
4
item.frm = (Form1)this.Parent;
5
item.SetParameter(this.TextBox1.Text);
6
item.ShowDialog();
7
}
Form2中:
1
public class FmItem : System.Windows.Forms.Form
2
{
3
public Form1 frm;
4
//省略若幹
5
public void SetParameter(string sValue)
6
{
7
this.TextBox1.Text = sValue1;
8
}
9
private void button1_Click(object sender, System.EventArgs e)
10
{
11
frm.TextBox1.Text = this.TextBox1.Text
12
MessageBox.Show("更新成功!","資訊");
13
this.Close();
14
}
15
}