PropertyGrid 多層摺疊使用方法:ide
///子子元素函數
public class school
{
public string Address{set;get;}
public string Name{set;get;}
public string Sex{set;get;}
public override string ToString()
{
return Address+Name+Sex;
}
}spa
///子元素
public class SystemConfig
{
public string ConfigName { set; get; }
private school _school = new school();
[TypeConverter(typeof(ExpandableObjectConverter)),Category("學生")]
public school MySchool1
{
set { _school = value; }
get { return _school; }
}blog
///
public override string ToString()
{
return ConfigName + MySchool1;
}
}ip
/// root元素
public class attributes
{
[Category("學生")]
public string Ages { get; set; }
private SystemConfig _config = new SystemConfig();
[TypeConverter(typeof(ExpandableObjectConverter)), Category("地址")]
public SystemConfig config
{
set { _config = value; }
get { return _config; }
}
}get
注意事項:string
1.重寫override 函數 返回當前類的member .it
2.自定義類保證必定構造了. 不然該類不顯示memberclass
3.自定義類使用[typeconverte(typeof(expandableobjectconverter))] 進行類型轉換object
4.category("標識屬於哪一個root下") ,displayName("標識顯示名稱") defaultvalue...
5.自定義編輯框 EditorAttribute(typeof(PropertyGridRichText),typeof(System.Drawing.Design.UITypeEditor))
自定義類 class PropertyGridRichText : UITypeEditor 等等.
Demo地址