Remove GenerateMember and Modifiers Properties in Designer
Asked Answered
S

3

6

I created a Button descendant where I hide all the properties I don't use.

I do it like this:

[Browsable(false)]
[Bindable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[Obsolete("", true)]
public new Boolean AllowDrop { get; set; }

Most properties get correctly hidden and cannot be used.

However there are two properties that I cannot get rid of.

enter image description here

Is there a way to also remove GenerateMember and Modifiers in the Designer?

Sella answered 26/7, 2016 at 6:27 Comment(0)
L
9

You can create a new ControlDesigner for your control and override its PostFilterProperties method. The method lets you to change or remove the items within the dictionary of properties.

The keys in the dictionary of properties are the names of the properties. Although Modifiers and GenerateMember are not actual properties of your control and they are design-time properties, you can still remove them this way:

using System.Windows.Forms;
using System.Windows.Forms.Design;
[Designer(typeof(MyCustomControlDesigner))]
public class MyCustomControl:Button
{
}
public class MyCustomControlDesigner:ControlDesigner
{
   protected override void PostFilterProperties(System.Collections.IDictionary properties)
   {
       base.PostFilterProperties(properties);
       properties.Remove("Modifiers");
       properties.Remove("GenerateMember");
   }
}

To hide properties in property grid, Instead of overriding or shadowing them, you can do the same thing for them.

Lou answered 4/8, 2016 at 15:7 Comment(0)
W
1

Somewhat offtopic. Mostly for those, who are struggling with disabling the "Dock in Parent Container" attribute. Following override helped me:

protected override void PostFilterAttributes(IDictionary attributes)
    {
        base.PostFilterAttributes(attributes);

        var oDockingAttribute = attributes.Values.OfType<DockingAttribute>().FirstOrDefault();
        var oNoDockingAttribute = new DockingAttribute(DockingBehavior.Never);

        if (oDockingAttribute != null) attributes[oDockingAttribute.TypeId] = oNoDockingAttribute;
    }
Wouldbe answered 12/11, 2019 at 11:19 Comment(0)
W
0

I don't think you can remove it because it is not a Class Property but a Design-Time Property and used only by the designer:

If you have played with Whidbey builds of Visual Studio, you may have noticed this new property called GenerateMember that shows up in the property grid for all controls and components you add to a Windows Form. Wondering what it is about? It is actually a design time extender property that allows you to control whether a component added to the form is referenced by a member variable in the class or a local variable in InitializeComponent. By default, it is set to true, but if you have any components that you are not really referencing outside of InitializeComponent, you can set it to false. That way you can limit the member variables in your class to only the components you really need member variables for – just something to prevent clutter.

Same applies to Modifiers and Locked.

Wiliness answered 26/7, 2016 at 6:31 Comment(1)
Although Modifiers and GenerateMember are not actual properties of a control and are design-time properties, but you can remove them by creating a custom Designer form control and overriding PostFilterProperties like I did here.Lou

© 2022 - 2024 — McMap. All rights reserved.