First, create a parent form form1 with the following controls: textbox1 and button1;
Create a subform form2 with the following controls: textbox2 and button2;
(First, describe the entire process: When you click form1's button1, open the form2 window, and enter any value in textbox2. When you click button2, pass the value of textbox2 to textbox1, that is, transfer values between forms)
Method 1:
Write the following in the click event of button1:Code:
Form2 F2 = new form2 ();
F2.showdialog (this );
Write the following code in the click event of button2:
Form1 F1 = (form1) This. owner;
F1.textbox1. Text = This. textbox2.text;
Run the command to pass the value.
Method 2:
Write the following code in the click event of button1:
Form2 F2 = new form2 (this );
F2.showdialog ();
Declare variables in the form form2 form class and rewrite the initialization constructor as follows:
Form1 form1;
Public form2 (form1 F1)
{
Initializecomponent ();
Form1 = F1;
}
Write the following code in the button1 click event:
Form1.textbox1. Text = This. textbox2.text;
Run the command to pass the value.
Note: The modifiers (control visibility level, namely modifier) of textbox1 should be one of public, internal, and protected and cannot be private ).