public void SetDatatypeShowOrHide(bool isShow)
{
PropertyDescriptor descriptor = TypeDescriptor.GetProperties(this.GetType())["IRButtonZWaveNodeId"];
BrowsableAttribute attri =(BrowsableAttribute)descriptor.Attributes[typeof(BrowsableAttribute)];
FieldInfo isBrow = attri.GetType().GetField("browsable", BindingFlags.NonPublic | BindingFlags.Instance);
isBrow.SetValue(attri, isShow);
}
"DataType"为propertyGrid中显示的属性。通过调用SetDatatypeShowOrHide()函数就可以动态设置DataType属性的显示和隐藏。
public void SetDatatypeReadOnly(bool isReadOnly)
{
PropertyDescriptor descriptor =
TypeDescriptor.GetProperties(this.GetType())["DataType"];
ReadOnlyAttribute attrib =
(ReadOnlyAttribute)descriptor.Attributes[typeof(ReadOnlyAttribute)];
FieldInfo isReadOnly =
attrib.GetType().GetField("isReadOnly", BindingFlags.NonPublic| BindingFlags.Instance);
isReadOnly.SetValue(attrib, isReadOnly);
}
通过调用函数就可以在程序的运行期间动态的设置属性是否Readonly。
propertyGrid动态(runtime)改变item的readonly 和browsable
最新推荐文章于 2023-06-26 20:56:08 发布