Inherent properties and event properties of component programming

Source: Internet
Author: User
In the previous chapter of programming, we created the simplest components, and today we talk about component's PropertyAttribute and Eventattribute.

Eventattribute are:

   BrowsableAttribute, CategoryAttribute, DescriptionAttribute, Defaulteventattribute

PropertyAttribute are:

   BrowsableAttribute, CategoryAttribute, DescriptionAttribute, Defaultpropertyattribute, DefaultValueAttribute 、 EditorAttribute, DesignerSerializationVisibilityAttribute, TypeConverterAttribute、 Bindableattribute, Localizableattribute

In this chapter of the tutorial we mainly talk about the red attribute, and then the designer UI will speak the blue attribute, the purple attribute does not explain.

The above attribute is concisely described as follows:

BrowsableAttribute: Visible in the property window.

Categoryattribute:property or which group the event belongs to.

A simple description of the Descriptionattribute:property or event.

Defaulteventattribute: Default event.

Defaultpropertyattribute: Default property, select the component, and its property window is selected by default on this property.

Defaultvalueattribute:property the default value of the selected component, which is selected by default on this event in its event window.

Using System;
Using System.Collections.Generic;
Using System.Text;
Using System.ComponentModel;

namespace components
{
PropertyAttribute, Eventattribute on the property, event, and [] enclosed.
Defaultpropertyattribute, Defaulteventattribute must be placed on the class head.
[DefaultEvent ("Customerlogout")]
public class Customer:component
{
private string _id;
private string _sex;
private int _age;
private string _address;
Private DateTime _createtime;

No CategoryAttribute, no descriptionattribute.
public string Id
{
get {return _id;}
set {_id = value;}
}

This property is in the customer's details group, and CategoryAttribute, DescriptionAttribute also applies to event.
[Category ("Customer's Details"), Description ("Customer's Sex")]//can write two attributes in one [].
public string Sex
{
get {return _sex;}
set {_sex = value;}
}

[Category ("Customer's Details")]
[Description ("Customer ' s Age"), DefaultValue (20)]
public int Age
{
get {return _age;}
set {_age = value;}
}

[DefaultValue ("Shanghai"), Category ("Customer's Details")]
public string Address
{
get {return _address;}
set {_address = value;}
}

[Browsable (FALSE)]//This property is not visible in the property window, BrowsableAttribute also applies to event.
Public DateTime Createtime
{
get {return _createtime;}
set {_createtime = value;}
}

public sealed class Customerlogineventargs:eventargs
{ }
public sealed class Customerlogouteventargs:eventargs
{ }

public delegate void Customerlogineventhandler (object sender, Customerlogineventargs e);
public delegate void Customerlogouteventhandler (object sender, Customerlogouteventargs e);

Public event Customerlogineventhandler Customerlogin
{
Add {}
Remove {}
}

Public event Customerlogouteventhandler Customerlogout
{
Add {}
Remove {}
}
}
}
Its property, event window is as follows:




I have not used DefaultValueAttribute, the above code in the address, the age in Customer1 created without DefaultValue, I will find out why, and in the next chapter, also want to know friends can tell.

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.