2. input values in the form
Form1 contains textbox1 and button1.
Lable1 in form2
To implement: click "button1" and then "form2". The content of lable1 is the content of textbox1.
ImplementedCode:
Code of the button in form1:
String T = textbox1.text; // Give the content to be displayed to a variable;
From2 Fr = new form2 (t); // form2 (t) is an overloaded constructor in form2
Fr. Show ();
Code in form2:
Private string m;
Public form2 (string P ) // Reload the constructor and add a parameter (used to pass the value) -- when the parameter is instantiated in form1 -- t is the content of textbox1.text, which replaces P
{
Initializecomponent ();
This. M = P; // Assign the parameter value to a private variable of form2
}
Form2_load ()
{
This. lable1.text = m; // Lable1 is the private variable M. At this time, M is the value T passed by form1.
}