This article continues to add, this is all a waste of my time to walk through the threshold
First, the inheritance relationship.
All custom controls inherit from UserControl, and of course you can derive the new class directly from the standard WinForm control, but the produced control cannot be used at design time, so you still have to do it in a good way. NET given the route to go. UserControl inherits from the base class control of standard controls so that user-defined controls do not differ from the standard controls at run time, but are very different at design time, and some properties do not work after override, as if the IDE had looked for the original property's get and set methods , the countermeasure is to hide this property and then replace it with a new name.
In order to make the behavior of this group of controls more manageable, the inheritance relationship between types should be reasonably arranged. Design a base class, responsible for all event response and function scheduling, in the derived class by overriding the base class corresponding method to complete the implementation of the UI, so that the level of logic will be clear and crisp, of course, the author I must think so, but my novice friends are questioning why to get more inheritance and rewrite.
Second, transparent color.
The focus of making irregular forms is to make the window BackColor and TransparencyKey the same, so that the background is hollow, the window's background is the effective range of the window. But wait, because WinForm after all the controls and background redraw window transparent processing, which led to the window, regardless of the background or control, as long as and the background color will be hollow, so the focus is to choose and sacrifice a less common color to the background, I chose LightGreen. Someone asked me what would happen if I had a hollow out? Click on the mouse point on the Windows desktop something on the chant.
Only PNG supports transparent colors in the static bitmap format that is recognized in window, but other formats can manually filter out a color to make it transparent. It is strongly recommended that the transparencykey of the window as the background of the bitmap, so filter out the bitmap after this color can not be a little bit of error so that users directly point to the desktop, only a pity that those materials are white background, helpless.
Three, the use of the characteristics
DescriptionAttribute, CategoryAttribute and Displaynameattribute these three big ye are propertygrid commonly used, here does not make the explanation
Defaulteventattribute acts on a type, defining the default event of the control, that is, the event that you double-clicked the control to trigger
ToolboxItemAttribute action on type, defines whether the control appears in the Toolbox
BrowsableAttribute A property, defines whether the property appears in the property box at design time, and uses it to hide properties that you do not want to be modified at design time
DefaultValueAttribute acts on a property, defining the default value of the property, which does not initialize the value of the property, and its effect: if the property equals this default value, it is displayed as non-bold in the property box. Popular saying is a humane not practical use
TypeConverterAttribute the type converter used when defining a designer assignment when the property value is not a value type commonly used by the system
EditorAttribute acts on attributes, property values in the Properties box of the advanced editing interface, such as the pop-up color selection box in the Properties box, the File selection box, the image source, and so on are the features in effect
Iv. Incident Response
Normally you should use normal event responses for events on the control itself, but I'm going to rewrite the controls for those on ... The beginning of the method, the benefit of doing so allows you to run the code before the event is triggered by viewing. NET source code, control in the integration is also all in Base.on ... Method that is triggered in the
Creating customizable styles for WinForm component Classes (ii) Summary of knowledge points