WinForm Creating a custom control

Source: Internet
Author: User

While vs gives us a lot of controls to use, sometimes these controls still don't meet our requirements, such as we want to personalize some of the controls, such as beautifying the controls, and then need to draw the controls yourself or modify them on the basis of the original controls.

There are three types of custom controls

1, combined control (Compositecontrols): Based on the original control according to the needs of the combination

2. Extended control (Extendedcontrols): Inherit from the original control, add some new properties and methods, draw some new elements

3. Custom Control (CustomControls): The drawing of the control is all user-defined

1. Combined controls

Create a new project and drag into the desired control, just as you would in a form

Compile builds to see the appearance of the control

The corresponding control library file can be found in the generated directory CompositeControl.dll

So the DLL for the combined control is ready, and the usage is followed by

2. Extended controls

First, add a class library

Referencing two namespaces System.Drawing and System.Windows.Forms, class renamed to Buttonex, inherited from button

Note that after the extension control is compiled, the visual tools cannot be called to view, only the DLL files are generated and need to be introduced into the project for use in order to see

3. Custom Controls

Custom controls are added in the same way as extended controls, except that the last class inherits from the control class.

The next step is to introduce the control library into the project using

If the project and the Control Library project are in the same solution, the control is automatically introduced to the Toolbox

If you are in a different project

Browse to select a library file, and then hook the control

To drag a control onto a form

Excerpted from http://www.cnblogs.com/bomo/archive/2012/12/09/2810559.html

WinForm Creating a custom control

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.