. Net WinForm user control development-(4) Basic Property settings of User Controls

Source: Internet
Author: User

In the previous sections, we demonstrated how to develop user controls. You may still be confused about the basic settings of some attributes in the user controls, in this section, we will learn about the basic property settings of user controls.

The so-called basic attribute settings mean that the control can set attributes in the property designer. Some attributes have default values in the design, and some in the property designer will pop up an editor, value.

This section

1. Simple data type attribute settings

2. attribute settings for complex data types

 

1. Simple data type attribute settings

Simple data types are common types in. NET, such as string, integer, floating type, and these basic data types.

Let's take a look at these basic attributes.

Browsable: indicates whether the property can be displayed in the property designer. If it is TRUE, it is displayed. If it is FALSE, it is not displayed.

Category: indicates the Category of an attribute.

Description: The Description of the property.

DefaultValue: the default value of the property.

Below we define a user control and customize a property SecondText. The Code is as follows:

[Csharp]
Public partial class UCLabel: UserControl
{
Public UCLabel ()
{
InitializeComponent ();
}
 
Private string _ sText = "Helloworld"; // Initial Value
/// <Summary>
/// Browsable indicates whether the property is displayed in the designer. TRUE indicates that the property is displayed.
/// </Summary>
/// Description indicates the Description of the attribute.
/// Category indicates the Category of this attribute in the property designer.
[Browsable (true)]
[Category ("text")]
[Description ("second text")]
[DefaultValue ("Sina Weibo")] // Default Value
Public string SecondText
{
Get
{
Return _ sText;
}
Set
{
_ SText = value;
}
}
 
 

}

Public partial class UCLabel: UserControl
{
Public UCLabel ()
{
InitializeComponent ();
}

Private string _ sText = "Helloworld"; // Initial Value
/// <Summary>
/// Browsable indicates whether the property is displayed in the designer. TRUE indicates that the property is displayed.
/// </Summary>
/// Description indicates the Description of the attribute.
/// Category indicates the Category of this attribute in the property designer.
[Browsable (true)]
[Category ("text")]
[Description ("second text")]
[DefaultValue ("Sina Weibo")] // Default Value
Public string SecondText
{
Get
{
Return _ sText;
}
Set
{
_ SText = value;
}
}



}

From the above picture, we can see the corresponding items of each attribute in the property designer.

Here, we will set the initial value of SecondText to HelloWorld and the default value to Sina Weibo. Let's talk about the difference between the initial value and the default value.

1. The initial value is the value assigned when the attribute is defined. When the user control is dragged onto the form, the initial value is displayed by default.

2. The default value of an attribute is non-bold, and other values are bold.

3. To restore the default value of a property, right-click the property and choose reset to restore the default value of the property.

 

2. Basic settings of complex attributes


 

Author: zx13525079024
 
 

 

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