Before Visual Studio. NET, most user interfaces must be designedCode. Although there were also VC and VB at that time, the functions of the VC/vB designer were still very weak. Although Java has a LayoutEngine, it can only be used to design a regular interface in most cases; although many ides also have visual designers, their performance still fails to meet our expectations. In this case, if we want to implement a complex interface, it will be a painful thing, And once implemented, it cannot be easily changed, otherwise, you have to re-adjust a widget several pixels and then run the project to see the effect countless times.
Visual Studio. the emergence of Net makes us shine, we only need to drag and drop on the Form Designer or other designer to complete most of the interface design, and almost everything is what you see is what you get, why!
Maybe you will be curious about how such a powerful designer works with me? Why can the correct code be generated by dragging and dropping on the designer? What happened to the Form Designer? Is there a form instance in it? After I drag a control from the toolbox to the form, do I actually create a control on the form? How is control implemented during design? How do I control my own control behavior during design?
If you are still curious about this, please follow this article to explore the mysteries of visual design. This is an introductory articleArticleIt is intended for beginners or friends who do not know much about designtime. Therefore, there will be no deep-seated knowledge, and it will not spread too far. If you are interested in a certain aspect or technical point mentioned in this article, please refer to msdn or others' blogs, or pay attention to some of my subsequent articles in this area.
First, I can tell you for sure that all the component, control, including form, and IDE you see on the designer have created actual objects in the memory. The form you see in the designer is where a form instance is placed, and a control on the form also has an actual control added to this form, just like the form interface you see after running this project. The difference is which form you run generatesProgramThe form in the designer converts your code into codedom and deserializes it into an instance from codedom.
Therefore, you can drag a control on the form or set a control attribute in the attribute window to modify the objects in the memory. So how do you generate code for object modification? The answer is also in codedom. Ide will serialize all components in your designer into codedom and then generate code from codedom. (For codedom, why codedom should be used here, and some other details will be described in future articles ).
There are only two most important operations on the Form Designer: one is to click and drag the form, and the other is to set the component attribute in the attribute window.
As you can see, the operations on the form on the mouse and keyboard in the designer are quite different from those on the form at runtime. After selecting a control, a dotted line and some hot spots will be drawn around the control. So how is this implemented? In fact, the form we see in the IDE designer has a two-layer transparent window. A layer of window is used to intercept messages. All the messages you operate on the form will be intercepted and processed by this layer of serial port. Therefore, you cannot click the close button in the upper right corner of the form to close the form, you cannot press a button on the form. Another window is used to draw decoration, such as a dotted line and a hotspot that appears around the control.
If you check the attribute on the component displayed in the attribute window, you will find that the attribute above is not the same as that on the component, and some attributes cannot be seen, some attributes do not work (such as the visible attribute), and some more attributes are added. There are many ways to influence attributes in propertywindow. First, some attributes, such as browsableattribute (adding a [browsable (false)] to the brain of an attribute can make it disappear in the attribute window ); second, some services, such as iextenderproviderservice (the name attribute of component is added through this tool); third, the visible attribute of control is replaced by the CAPTCHA here through prefilteproperties on componentdesigner) and postfilterproperties; 4. Set typedescriptor. This is the most fundamental method. In fact, the first three methods are actually implemented through typedescriptor. I will write articles about typedescriptor in the future.
Here, I will mention the designerattribute. Most of the actions of component in the designer are implemented through designer. You can add a designer to your component, your own designer should be inherited from componentdesigner or its derived class (such as controldesigner. In your designer, you can override the actionlists attribute to customize the Smart tag. You can override the verbs attribute to add a menu item in the context menu; if it is derived from controldesigner, snaplines can also customize the adsorption effect when dragging. Assume that your designer is called mydesigner and your component is called mycomponent. The method for attaching mydesigner to mycomponent is to add an attribute to the mycomponent class: [designer (typeof (mydesigner)].
Well, the introduction to the Visual Studio designer is here first. If you are interested in this part of content, please continue to follow this blog. If you have any questions or ideas, please have a discussion.