In the past, the instructor mentioned an example of passing values by performing operations on properties in forms and classes ..
Unexpectedly, I did not find it after searching on the csdn. Web for a long time.ArticleI am inspired to write my own data transfer method ....
There are several ways to pass the value... form fm = new form (parameter) is my most disapproval ........
There is no need to delegate... the static field is too limited ..
Namespace readfile
{
Public partial class form2: Form
{
Public form2 ()
{
Initializecomponent ();
}
Private void button#click (Object sender, eventargs E)
{
Form3 fm = new form3 ();
FM. _ Val = This. textbox1.text;
If (FM. showdialog () = dialogresult. OK)
{
This. textbox1.text = FM. _ Val;
}
}
}
}
Namespace readfile
{
Public partial class form3: Form
{
// Define an attribute
Public String _ Val;
Public String Val
{
Get
{
Return _ Val;
}
Set
{
_ Val = value;
}
}
Public form3 ()
{
Initializecomponent ();
}
Private void button#click (Object sender, eventargs E)
{
_ Val = This. textbox1.text;
This. dialogresult = dialogresult. OK;
This. Hide ();
}
Private void form3_load (Object sender, eventargs E)
{
This. textbox1.text = _ Val;
}
}
}