这里主要介绍方法3、4
方法3:
Step 1: Add a property in form1 to retrieve value from textbox.
Step 2: Add a property in form2 to set the labels’ text
Step 3: In form1’s button click event handler add the following code.
方法4:
Step 1: Add a delegate signature to form1 as below
Step 2: In form1’s button click event handler instantiate form2 class and delegate. Assign a function in form2 to the delegate and call the delegate as below
Step 3: In form2, add a function to which the delegate should point to. This function will assign textbox’s text to the label.
详细介绍请参考:http://www.codeproject.com/useritems/pass_data_between_forms.asp
FrmM: txt1、txt2、txt3的Modify设为:Public
private void btn1_Click(object sender, EventArgs e)
{
FrmS fs = new FrmS();
fs.Owner = this;//Owner:拥有当前窗体的窗体
fs.ShowDialog();
}
FrmS:
private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
FrmM fm = (FrmM)this.Owner;
fm.txt1.Text = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
fm.txt2.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
fm.txt3.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
this.Close();
}