c# PropertyGrid 多层折叠 示例

PropertyGrid 多层折叠使用方法:

///子子元素

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;
        }
    }

///子元素
    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; }
        }

  ///
        public override string ToString()
        {
            return ConfigName + MySchool1;
        }
    }

/// 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; }
        }
    }

注意事项:

1.重写override 函数 返回当前类的member .

2.自定义类保证一定构造了. 否则该类不显示member

3.自定义类使用[typeconverte(typeof(expandableobjectconverter))] 进行类型转换

4.category("标识属于哪个root下") ,displayName("标识显示名称") defaultvalue...

5.自定义编辑框 EditorAttribute(typeof(PropertyGridRichText),typeof(System.Drawing.Design.UITypeEditor))

自定义类 class PropertyGridRichText : UITypeEditor 等等.

 

Demo地址

 

转载于:https://www.cnblogs.com/nameliu/p/3325410.html

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值