作用:使用PropertyGrid控件可以与属性进行连接,自动生成属性表格。
上代码:
//创建一个属性类 public class Employee { [Category("Info"),Browsable(false)] public Guid ID { get; set; } [Category("Info"),DisplayName("姓名")] public string FirstName { get; set; } [Category("Info"),Description("这是一段描述")] public string LastName { get; set; } [Category("Info"),Range(1,99)] public int Age { get; set; } [Category("Job")] public Double Salary { get; set; } [Category("Job")] public string Position { get; set; } [Category("Job")] public string Department { get; set; } }
与PropertyGrid控件进行连接
var employee = new Employee { ID = Guid.NewGuid(), FirstName = "Tom", LastName = "Riddle", Age = 25, Salary = 10000, Position = "Software Engineer", Department = "Development" }; propertyGrid1.SelectedObject = employee;
效果:
标签:Category,Info,set,string,get,C#,使用,PropertyGrid,public From: https://www.cnblogs.com/Coder-Echo-Lee/p/16737246.html