1

Is it possible to remove a form property or set of properties from the Properties pane in Visual Studio?

Backstory: I've made some UserControls which inherit the common form properties, but I want to remove the "Anchor" and "Dock" properties from the Properties pane in Visual Studio, since the UserControl will be using different resizing logic, logic that anchoring and docking don't seem to support.

I'm thinking it's an annotation of some kind, but I'm not entirely sure, and I wasn't able to find anything on Google.

Thanks in advance!

4

4 に答える 4

3

必要な属性は Browsable です http://msdn.microsoft.com/en-us/library/system.componentmodel.browsableattribute.browsable.aspx これらのユーザー コントロールで Dock と Anchor をオーバーライドし、その属性を (「false」値で) 追加します。 )それらに追加して、それが機能するかどうかを確認します(デザイナーが変更をロードできるように、必ず再コンパイルしてください)

于 2012-06-05T21:03:26.907 に答える
3

Browsable 属性をプロパティに追加してみてください。

using System.ComponentModel;

[Browsable(false)]
public override AnchorStyles Anchor {
  get {
    return base.Anchor;
  }
  set {
    base.Anchor = value;
  }
}
于 2012-06-05T21:03:44.683 に答える
1

プロパティをオーバーライドしたくない場合は、プロパティ グリッドに表示される内容を制御するために、コントロールに 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;
}
于 2012-06-05T21:33:31.637 に答える
0

プロパティをオーバーライドし、Browsable属性を false に設定します。

[Browsable(false)]
public override AnchorStyles Anchor
{
    get
    {
        return AnchorStyles.None;
    }
    set
    {
       // maybe throw a not implemented/ don't use message?
    }
}

[Browsable(false)]
public override DockStyle Dock
{
    get
    {
        return DockStyle.None;
    }
    set
    {

    }
}
于 2012-06-05T21:07:41.140 に答える