In my "MDI form mutual call 1" article, I have explained how to make the MDI windows call each other.
However, the method used in the previous article uses the basic features of the "reference type". In the following method, I use the class definition to complete the above functions. In general, I do not approve of your use of the second method. The second method mentioned here is just to be discussed with you!
My second method is (assuming the main window is form1 and the subwindow is form2)
Nothing needs to be changed in the main form
The main form is hidden when the subform is displayed using the following code:
Form2 form2 = new form2 (this); // you may be curious. Why do you have a parameter here?
Form2.show ();
This. Hide ();
In addition, the Code does not need to be changed anywhere else in the main form. In the second method, we completely rewrite the code in the subform.
The code in the subform is as follows:
First, we need to change the form2 constructor, because form2 form2 = new form2 (this); appears in form1.
Public partial class form2: Form
{
Private form1 F1 = NULL; // a form is defined here! References
Public form2 (form1 parentform) // this parameter is added by myself
{
F1 = parentform; // In fact, this is the key. I pass an F1
Initializecomponent ();
}
// Other code
}
Here, I will define F1 as a private member, mainly to control the F1 scope, so security is the first.
In the main form, I use this as a row parameter and pass it to public form2 (form1 pearentform), because in the main form, this refers to form1 itself!
All of the above methods are in VS 2005. methods and method 2 are the same. They all use the reference type feature, but the implementation methods are a little different, actually, method 1 is simpler than method 2.
So why should I use method 2? Here, I feel that C #. NET is the operating mechanism of C #. net, and its keypoint is the most important thing to learn. In fact, the most important thing to learn any programming language is to clear its operating mechanism and its keypoint. There is also more hands-on, more brains!