C # How do I customize controls? Today, I want to customize the controllability of controls.
The process of designing custom attributes is very simple. You only need to consider the following aspects before designing attributes:
- What is the purpose of using attributes?
Attributes can be used in many ways. You need to define what functions the attributes need to complete and ensure that these specific functions are not built in the. NET Framework set. Using the. NET modifier is better than using properties because it simplifies the integration process with other accessories.
- What information must the attribute store?
Is the attribute intended to indicate a simple identifier of a function? Or do attributes need to store information? A property can have a set of information assigned during design and view the information at runtime. For example, let's take a look at the alias attributes in the example application.
- Which accessories should the attribute reside in?
In most cases, attributes can be included in accessories that use these attributes. However, it is better to place attributes in public, lightweight, and shared accessories. This type of configuration allows customers to use properties without referencing unwanted accessories.
- Which accessories will recognize attributes?
If there is no module read attribute, it will be worthless. You may put the class that reads the attribute in the same assembly where the attribute resides. However, as mentioned above, you want to put the methods and attributes for reading attributes in different accessories.
/// <Summary>
/// Customize filetype adequacy
/// </Summary>
String Sfiletype = " * " ;
// Browsable: gets a value that indicates whether the object can be renewed.
[Browsable ( True )]
// Defaultvalue: gets the object, which contains the preset value related to the organizational consistency.
[Defaultvalue ( " * " )]
// Category: name of a property score or an event applied to this attribute.
[Category ( " Basic_property " ), Description ( " The file type is added when the router interface is used. " )]
Public String Filetype
{
// Value Method
Get
{
Return Sfiletype;
}
// Assignment Method
Set
{
Sfiletype = Value;
// When the consistency is used, in order to view the result, set the value of the txtbox control
If (Sfiletype = " C # " )
{
This . Text = " C # " ;
}
Else
{
This . Text = " ??? " ;
}
}
}
Note:
If you only set get {...}, it indicates that it is only partial.
If only set {...} is set, it indicates that it is only experimental. Only valid values are used to protect data such as passwords. Ideally, security-preserving applications are requiredProgramAllowed to set the password, but you may not allow it to appear. A login method should only use the password provided by login to compare with the password provided by the storage, and return whether the two match messages.
Exam: http://www.pcdog.com/edu/csharp/2007/04/j184921.html