Developing a simple composite control with Visual C #

Source: Internet
Author: User

This article describes how to develop simple composite controls (composite control) with Visual C #. NET 2002, which focuses on properties and event handling during control development to facilitate developers. NET platform to develop the appropriate controls according to your own needs.

When we were in. NET platform, you often need to combine existing controls for a particular purpose, such as controls that combine labels and textbox, that are easy to lay out on a form (remember that there is a control in Delphi 6), Controls that combine specific patterns and text are ideal for displaying your company's logo. NET platform provides us with a great tool and technology to create such custom controls. Let's create a control that can automatically display the time.

It's worth noting that. NET platform provides us with the development techniques for three kinds of controls: inherited controls (Extended control), composite controls (composite control), and custom controls (custom control) (the translation may be different, you can use English as the standard )。 We are now concerned with the second-composite control. Ok,let ' s go!

1. Create a control project.

In Visual C #. NET to create a new Windows Control Library project named "Timelabel"

2. Change the namespace, control class name.

The default namespace is Timelabel (like the project name), and the control class name is UserControl1. Please change the namespace to be consistent with your development habits, If mine is LeoYang.Controls.TimeLabel, of course you can also choose to keep the default namespace; it is better to change the control class name to a meaningful name, such as Timelabel, so that when the control appears on the toolbox, it will appear as Timelabel instead of UserControl1. 。 Note that once the class name is altered, the corresponding construction method name should also be changed accordingly, such as:

public UserControl1()

should read:

public TimeLabel()

3. Add an existing control.

Since we are creating new controls on the basis of existing controls, we should first add the existing controls available to the control design interface. Double-click the label in the Toolbox, and then double-click the timer, and two existing controls are added to our design interface in turn, as shown in Figure 2:

Related Article

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: 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.