C#,Winform中PropertyGrid控件的使用
PropertyGrid的功能不用我多说了,看名字就可以知道个大概,在这里就谈谈它的一些功能使用。
假设目前有一个PropertyGrid控件PropTableColumn,那么进行属性绑定只需要一句话:
this.PropTableColumn.SelectedObject = ... ;
其中...表示需要进行绑定的对象,PropertyGrid使用的广泛性也主要体现在对象的设计上.
假设我们目前设置了一个类ABSControlsSettings用于绑定,代码如下:
public class ABSControlsSettings ![]()
{
public ABSControlsSettings() ![]()
{
}
}那么这个类就可以用于绑定,只是什么属性都没有而已,OK,现在我们加入一个ID属性的维护输入,其代码和加入一个普通的类属性没有什么区别
private string _ControlID;
public string ControlID ![]()
{ ![]()
get
{ return _ControlID; } ![]()
set
{ _ControlID = value; }
}此时我们可以通过添加一系列属性来完善它,如
CategoryAttribute("System")
ReadOnlyAttribute(false)
DescriptionAttribute("Controll's ID")
这个只是最普通的属性,如果属性需要设置true or false,那么只需要这样设置
private bool _Needcheck;
public bool Needcheck ![]()
{ ![]()
get
{ return _Needcheck; } ![]()
set
{ _Needcheck = value; }
}
如果是一个需要进行多项选择,如同BorderStyle之类的参数,可以通过枚举属性来实现
private ControlTypeEnum _ControlType = ControlTypeEnum.Label;
public ControlTypeEnum ControlType ![]()
{ ![]()
get
{ return _ControlType; } ![]()
set
{ _ControlType = value;}
}
public enum ControlTypeEnum ![]()
![]()
{ ![]()
/**//// <summary>
/// 标签
/// </summary>
Label = 1, ![]()
/**//// <summary>
/// 文本框
/// </summary>
TextBox = 2
}

浙公网安备 33010602011771号