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.