propertyGrid控件加号显示(复杂属性显示)

 Layer _zd = new Layer("ZD");
       [TypeConverter(typeof(ExpandableObjectConverter))]
        public Layer zd
        {
            get
            {
                return _zd;
            }
            set
            {
                _zd = value;
            }
        }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
PropertyGrid 是一个 Windows 窗体件,它允许您在运行时显示和编辑对象的属性集合。要指定在 PropertyGrid显示属性,您可以使用 BrowsableAttribute。 BrowsableAttribute 是一个属性类,用于属性是否在 PropertyGrid显示。如果未将 BrowsableAttribute 应用于属性,则该属性默认为可浏览的。如果将 BrowsableAttribute 设置为 false,则属性将在 PropertyGrid 中隐藏。 以下是一个示例,演示如何在 PropertyGrid 中指定可显示属性: ```csharp public class Person { [Browsable(true)] // 可显示属性 public string Name { get; set; } [Browsable(false)] // 不可显示属性 public int Age { get; set; } } ``` 在上面的示例中,Person 类具有两个属性:Name 和 Age。由于 Name 属性上的 BrowsableAttribute 设置为 true,因此该属性将在 PropertyGrid显示。另一方面,由于 Age 属性上的 BrowsableAttribute 设置为 false,因此该属性将在 PropertyGrid 中隐藏。 您还可以在运行时动态更改属性的可浏览性。例如,以下代码演示如何在单击按钮时将 Name 属性设置为不可浏览: ```csharp private void button1_Click(object sender, EventArgs e) { PropertyDescriptor property = TypeDescriptor.GetProperties(typeof(Person))["Name"]; BrowsableAttribute attribute = (BrowsableAttribute)property.Attributes[typeof(BrowsableAttribute)]; property.Attributes.Remove(attribute); property.Attributes.Add(BrowsableAttribute.No); propertyGrid1.Refresh(); } ``` 在上面的代码中,我们使用 TypeDescriptor.GetProperties 方法获取 Name 属性的 PropertyDescriptor 对象。然后,我们获取该属性上的 BrowsableAttribute,并将其替换为 BrowsableAttribute.No。最后,我们调用 PropertyGrid 的 Refresh 方法,以便更新显示

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值