在设计时更改属性属性,如ReadOnly(PropertyGrid)

时间:2009-10-10 18:30:46

标签: c# winforms attributes properties propertygrid

我开发了一个自定义控件,其中包含以下字段:

ControlKind,Field1,Field2

我想改变每个controlKind,
字段之一的属性 例如:如果controlKind == useField1,那么Field1 show和Field2 hidde in properyGrid(或readonly或filter)

我能做到吗?

提前致谢

1 个答案:

答案 0 :(得分:4)

实现ICustomTypeDescriptor,或注册TypeDescriptionProvider并从中返回自定义类型描述符,或应用TypeConverterAttribute。

在所有这三种情况下,您需要实现/覆盖GetProperties方法以返回实际属性的已过滤子集。 (在TypeConverter方法中,您还必须重写GetPropertiesSupported以返回true。)