| using System; using System.Collections.Generic; using System.Text; using System.ComponentModel; namespace Components { // PropertyAttribute、EventAttribute分别放在Property、Event上,并[]括起来。 // DefaultPropertyAttribute、DefaultEventAttribute必须放在类头上。 [DefaultEvent("CustomerLogout")] public class Customer : Component { private string _id; private string _sex; private int _age; private string _address; private DateTime _createTime; // 没有CategoryAttribute、DescriptionAttribute。 public string Id { get { return _id; } set { _id = value; } } // 此属性在Customer's Details分组中,CategoryAttribute、DescriptionAttribute也适用于Event。 [Category("Customer's Details"), Description("Customer's Sex")] // 可以在一个[]里写两个Attribute。 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)] // 此Property在Property窗口中不可见,BrowsableAttribute也适用于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 { } } } } |
![]() ![]() |
关注此文的读者还看过: