Define the default value of component properties

xiaoxiao2021-03-06  19

There are two specified methods for the default value of the component properties:

First, describe the characteristics of the attribute

For example, as follows, a class of properties

Public Class Myclass

{

Private int myproperty;

[DefaultValue (3)]]

Public int myProperty

{

Get {return myproperty;}

set

{

IF (MyProperty! = Value)

MyProperty = VALUE;

}

}

....

}

More common features Description is the definition of [DefaultValue (typeof (), )] Where is a common data type such as Color, Font, Point, Int, String, Float ..., < FormatString> The format text string output by (usually this, of course, if the type defined when the type is defined, the format is different), the following example:

[DefaultValue (TypeOf (Color), "White")] and

[DefaultValue (TypeOf (Point), "{x = 110, y = 120}")], etc. ...

Second, use the ShouldSerialIze method

The particularity of this method is that the method's naming has an agreement, and the naming must be started at the ShouldSerialize, and then the return type must be a BOOL type. The method implementation to define this property and the default value of the default value, if the designer is called this After the method, Returns true, which is displayed at the bold, which is usually used for some of the complex class properties, such as font, or custom types. In addition, the generally excellent design also implements the Reset method to activate the Reset menu item in the designer.

For the characteristics of component properties, please see the "RAD component written with .NET property window interact"

http://blog.9cbs.net/zoulNG/Archive/2005/03/23/328215.aspx

转载请注明原文地址:https://www.9cbs.com/read-43418.html

New Post(0)