プロパティをオーバーライドしたくない場合は、プロパティ グリッドに表示される内容を制御するために、コントロールに ICustomTypeDescriptor を実装することができます。これを行うには、実装を標準実装 (TypeDescriptor の静的メソッド) に委譲するプロパティを返すメソッドとは別に、すべてのメソッドを実装できます。これらのメソッドの実装は次のようになります。
public String GetClassName()
{
return TypeDescriptor.GetClassName(this,true);
}
public AttributeCollection GetAttributes()
{
return TypeDescriptor.GetAttributes(this,true);
}
public String GetComponentName()
{
return TypeDescriptor.GetComponentName(this, true);
}
public TypeConverter GetConverter()
{
return TypeDescriptor.GetConverter(this, true);
}
public EventDescriptor GetDefaultEvent()
{
return TypeDescriptor.GetDefaultEvent(this, true);
}
public PropertyDescriptor GetDefaultProperty()
{
return TypeDescriptor.GetDefaultProperty(this, true);
}
public object GetEditor(Type editorBaseType)
{
return TypeDescriptor.GetEditor(this, editorBaseType, true);
}
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{
return TypeDescriptor.GetEvents(this, attributes, true);
}
public EventDescriptorCollection GetEvents()
{
return TypeDescriptor.GetEvents(this, true);
}
public object GetPropertyOwner(PropertyDescriptor pd)
{
return this;
}
実装する必要があるメソッドは GetProperties です。あなたの場合、非表示にしたいものを除いてすべての PropertyDescriptor を含む必要がある PropertyDescriptionCollection を返します。このようなもの:
public PropertyDescriptorCollection GetProperties()
{
pdColl = new PropertyDescriptorCollection(null);
foreach (PropertyDescriptor pd in TypeDescriptor.GetProperties(this))
if (pd.Name != "Dock" && pd.Name != "Anchor")
pdColl.Add(pd);
return pdColl;
}