Open the form constructor execution from the designer

Source: Internet
Author: User

When I tested the designMode a while ago, I found that the results were always inconsistent with expectations. I haven't figured it out for a long time.
Recently, I happened to think of one thing. Conjecture may be related to this. So I tested it. The test results are recorded as follows:
Test 1: When the form is opened from the designer, whether to execute the constructor to test the current constructor and the base class constructor respectively.
Test process:
Add two forms: frmdisignmodetestbase and frmdisignmodetest. frmdisignmodetest inherits from frmdisignmodetestbase. Write some tests into the constructor. Code :
Public frmdesignmodetestbase ()
{
Initializecomponent ();
Label1.text = "base constructor has been executed ";
}
Public frmdisignmodetest ()
{
Initializecomponent ();
Label2.text = "constructor has been executed ";
}
Compile Program Open the frmdisignmodetest from the designer. We can see that the constructor of frmdisignmodetest is not executed, but the frmdisignmodetestbase is executed.
Test result: when the form is opened in the designer, the form base class constructor is executed and the current class constructor is not executed.
During the test, we also found a phenomenon: when the base class constructor is modified and the derived form is opened without generating a program, you can see that the base class constructor executed is the code before modification. After the code is re-generated, the base class constructor executed is the modified Code. After verification, the result is true.
It can be inferred that when a form is opened in IDE, the control is loaded from the Assembly where the base class is located and its constructor is executed.
Note: No matter whether the program is compiled first, the current constructor of the form will not be executed when the form is opened.
Note: When a composite control is added to the IDE, The designMode of its internal child control fails. If a control is inherited, the base class's designMode will not expire when the control of the derived class is used in IDE.

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.