vantusiatina, вот накидал:
| Код | public class MyCustomTypeDescriptor : CustomTypeDescriptor { private List<string> _shadowedProperties; private Type _shadowedType; public MyCustomTypeDescriptor(Type shadowedType, string[] shadowedProps) { this._shadowedType = shadowedType; this._shadowedProperties = new List<string>(shadowedProps); } private PropertyDescriptorCollection FilterProps(PropertyDescriptorCollection props) { if (props == null) return null;
List<PropertyDescriptor> validProps = new List<PropertyDescriptor>(); foreach (PropertyDescriptor pd in props) { if (!_shadowedProperties.Contains(pd.Name)) { validProps.Add(pd); } }
return new PropertyDescriptorCollection(validProps.ToArray()); }
public override PropertyDescriptorCollection GetProperties() { return this.FilterProps(TypeDescriptor.GetProperties(_shadowedType)); }
public override PropertyDescriptorCollection GetProperties(Attribute[] attributes) { return this.FilterProps(TypeDescriptor.GetProperties(_shadowedType, attributes)); } }
|
| Код | public class MyTypeDescriptionProvider : System.ComponentModel.TypeDescriptionProvider { public override System.ComponentModel.ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object instance) { if (objectType == typeof(Button)) { return new MyCustomTypeDescriptor(objectType, new string[] {"Visible", "Enabled"}); } return base.GetTypeDescriptor(objectType, instance); } }
|
| Код | ... private void button1_Click(object sender, EventArgs e) { TypeDescriptor.AddProvider(new MyTypeDescriptionProvider(), button1); this.propertyGrid1.SelectedObject = this.button1; } ...
|
Идея ясна? |