Making WinForm components with Visual C #

Source: Internet
Author: User

We know. NET's development platform is a namespace System.Windows.Forms, which provides many classes and objects to develop Windows form that are not only rich in content, but also very powerful extensibility, and can be leveraged to use these classes and objects. Simple and rapid development of the components you need to. This article will explain how to use the. Net development platform's original classes and objects to write a WinForm component of your own, how to compile your own components, and how to use it in a client program.

I. Basic environment for programming and operation:

(1). Windows 2000 Server Edition

(2). Net FrameWork SDK Beta version 2

Two. Introduction to the component features developed in this article:

(1). The component developed in this article is a custom component that is merged with two components, one is the label component (lable) and the other is a text box component (textbox).

(2). There are two new properties defined in the custom component, one property is text, which is obtained by deriving the Text property from the original TextBox, and the other property is LabelText, which is obtained by inheriting the original label's Text property.

(3). The purpose of the component.

In programming, it is often time to define a label that displays the text to be entered. Then define a text box and fill in the information. Once this component is used, it is OK to define one of these components and then set different values for the component properties. This simplifies the programming process. This will be reflected in the later component applications.

Three. Difficulties and priorities in the development component:

(1). How to set the contents of a custom component:

This component consists of a label component and a text box component that first defines the composition of this component. The specific program design is as follows:

//LabledTextBox组件是继承了 UserControl组件的
public class LabeledTextBox : UserControl
{
 //定义本组件的组成结构
 private Label myLabel ;
 private TextBox myTextBox ;
 ……
}

(2). How to derive the Text property in the textbox and generate your own new property:

The Text property of the textbox is derived so that the keyword "override" is used in the program. And the "get" keyword is used to read the component's property values through the keyword "set" Setting property. The specific procedure is designed as follows:

//组件中的Text属性,是从文本框的Text的属性派生而来
public override string Text
{
 get
 {
  return myTextBox.Text ;
 }
 set
 {
  myTextBox.Text = value ;
 }
}

(3). How to create a new property labeltext, and this property value is obtained by inheriting the "Text" property of an existing label. The specific program design is as follows:

//创建一个新的属性LabelText,并且此属性的值是通过继承此组件中的标签的Text属性值
public string LabelText
{
 get
 {
  return myLabel.Text ;
 }
 set
 {
  myLabel.Text = value ;
 }
}

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.