![]() |
![]() |
![]() |
屬性值 | 含義 |
CategoryAttribute | 該屬性對在Property控件中的屬性按字母順序進行歸類 |
DescriptionAttribute | 其值為對每個屬性的具體文字描述,將會顯示在property控件的底部 |
BrowsableAttribute | 該值為是否在property控件中顯示或者隱藏某個屬性 |
ReadOnlyAttribute | 該值為某個屬性值是否在property控件中只讀 |
DefaultValueAttribute | 每個屬性的默認值 |
using System.ComponentModel; |
/// Customer class to be displayed in the property grid /// </summary> /// [DefaultPropertyAttribute("Name")] public class Customer { private string _name; private int _age; private DateTime _dateOfBirth; private string _SSN; private string _address; private string _email; private bool _frequentBuyer; [CategoryAttribute("ID Settings"), DescriptionAttribute("Name of the customer")] public string Name { get { return _name; } set { _name = value; } } [CategoryAttribute("ID Settings"), DescriptionAttribute("Social Security Number of the customer")] public string SSN { get { return _SSN; } set { _SSN = value; } } [CategoryAttribute("ID Settings"), DescriptionAttribute("Address of the customer")] public string Address { get { return _address; } set { _address = value; } } [CategoryAttribute("ID Settings"), DescriptionAttribute("Date of Birth of the Customer (optional)")] public DateTime DateOfBirth { get { return _dateOfBirth; } set { _dateOfBirth = value; } } [CategoryAttribute("ID Settings"), DescriptionAttribute("Age of the customer")] public int Age { get { return _age; } set { _age = value; } } [CategoryAttribute("Marketting Settings"), DescriptionAttribute("If the customer has bought more than 10 times, this is set to true")] public bool FrequentBuyer { get { return _frequentBuyer; } set { _frequentBuyer = value; } } [CategoryAttribute("Marketting Settings"), DescriptionAttribute("Most current e-mail of the customer")] public string Email { get { return _email; } set { _email = value; } } public Customer() { } } |
private void Form1_Load(object sender, System.EventArgs e) { //創建bill對象,實例化CUSTOMER類 Customer bill = new Customer(); //賦值給屬性 bill.Age = 50; bill.Address = " 114 Maple Drive "; bill.DateOfBirth = Convert.ToDateTime(" 9/14/78"); bill.SSN = "123-345-3566"; bill.Email = “bill@aol.com” bill.Name = "Bill Smith"; //將對象綁定到property控件中 propertyGrid1.SelectedObject = bill; } |
新聞熱點
疑難解答