. NET component Control instance programming series--1. Opening

Source: Internet
Author: User

There are already a lot of articles about components and controls on the Web, and I'm learning these technologies slowly through these articles. But those articles are mainly tutorial-style, given the example is simple and easy to understand, but the actual application of the case is relatively small. Here I have done in the work and study of the components and control of the implementation methods posted, I hope to help beginners. Of course, my code will also have a lot of problems, some solutions are not perfect, I hope to see friends do not hesitate to enlighten.

First of all, I referred to the series of links posted, there are more detailed tutorials, for beginners to help larger.

. NET component Programming http://www.cnblogs.com/mapserver/category/65343.html

WinForm Control Development Http://www.cnblogs.com/guanjinke/category/77694.html

To learn about component control programming, you must first understand the PropertyGrid control and related attributes, which are described in more detail in the reference articles given above.

With regard to controls, there is no need to explain too much, and components are widely used without controls. The most intuitive understanding is that the control is visible at runtime and that the component is not visible at run time. Controls are typically used to interoperate with the user, and the component encapsulates the business logic. When I'm programming, components are usually attached to specific controls that provide a certain business function for the control. And I tend to use components a lot of the time, and here's an analysis of the advantages of a component relative to a control.

For example, to add a function x to a control a, the control's method is to inherit control a, and then implement function x in the new control B. If you need to add function y to control A, continue with the control's method, you will need to create another control C to inherit control A, and then implement function Y. But if you do the above work, you need to add both feature x and function y to control a, or you need to add feature X to control D, you must create more controls. This will result in a proliferation of controls that are not conducive to management.

If you use components, the situation is very different. To create a component that encapsulates function x and function y, you need to add function X to control A, drag and drop component x onto the form, and set a property of component X to be specified as control a. If you need to add the function y, it's exactly the same as the previous step. If you need to add functionality to control D, the component's interface supports control D exactly as it does for control a. As such, adding functionality to a control is as easy as building a building block. Each function requires only one component to implement, and then binds the control that needs to add the corresponding functionality to the component.

The idea of a component also conforms to one of the basic principles of programming: First, combine and inherit. The application of the component is more flexible than the control, so in many cases I will choose the component. Another principle is that a component encapsulates only one function and does not encapsulate multiple functions into one component in a try, which reduces the flexibility of the component.

This is the beginning of this article, starting with an example of how to implement component control programming.

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.