C #. Net learning notes-two mutual calls for MDI forms

Source: Internet
Author: User
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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.