扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:廖煜嵘编译 来源:天极软件频道 2007年11月13日
关键字:
属性值 | 含义 |
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; } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者