If you want to use winform to write something, you may encounter a depressing problem. If you want to transfer values between forms, you may encounter difficulties. Find a solution on the Internet and create one. Suppose you want to create form2 in form1 and form2 to access form1, the simplest way is to add
Public Form1 parent;
When form1 is created as follows:
Form2 F2 = New Form2 ();
F2.parent = This ;
F2.show ();
In form2, you can use parent to access form1.
However, if form1 and form2 have no parent-child relationship, form2 is not created in form1, and form2 is not created in form1. How can we get the instance of the other party? Form1 is used as an example. We create another form and use it to instantiate other forms, such as starter.
Add the static variables F1 and the static method getform1 () in starter ():
Class starter
Public Partial Class Starter: Form
{
Public Static Form1 F1;
Public Static Form1 getform1 ()
{
If (F1 = Null )
{
F1= NewForm1 ();
}
Return F1;
}
Public Starter ()
{
Initializecomponent ();
Getform1 (). Show ();
}
}
You can use starter. getform1 () to get F1. Set starter to minimize startup. If it is not displayed in the status bar, we will not see it.
PS: We also found that any event's xxxing () processing function can include eventargs e of the event. if cancel is set to true, the event is canceled. It is only now that this useful stuff is known... -_-