How do I hide some of the default control properties at design-time (C#)?

11,135

Solution 1

You could either override them (if they can be overriden) and apply the Browsable attribute, specifying false, or create a new version of the property and apply the same attribute (this second approach doesn't always appear to work so YMMV).

Also, you can use a custom TypeConverter for your type and override the GetProperties method to control what properties get displayed for your type. This approach is more robust to the underlying base classes changing but can take more effort, depending on what you want to achieve.

I often use a combination of the Browsable attribute and a custom TypeConverter.

Solution 2

Override the property and add [Browsable(false)].

You might also want to add [EditorBrowsable(EditorBrowsableState.Never)], which will hide the property in IntelliSense in the code editor. Note that it will only be hidden in a separate solution from the original control.

Solution 3

using System.ComponentModel;

[Browsable(false), DesignerSerializationVisibility(
                            DesignerSerializationVisibility.Hidden)]
public int MyHiddenProp {get; set; }

worked for me in that way, that it would not appear in designer-properties, AND the propertiy will not be initialized by the designer, which would override my own initialisation....

Share:
11,135
Alex F
Author by

Alex F

Lifetime computer geek. I started on a VIC20, and now I have several computers running both linux and windows. I program hack around on them for fun in my spare time, and program PLCs for a living.

Updated on July 10, 2022

Comments

  • Alex F
    Alex F almost 2 years

    I have a custom control that I made. It inherits from System.Windows.Forms.Control, and has several new properties that I have added. Is it possible to show my properties (TextOn and TextOff for example) instead of the default "Text" property.

    My control works fine, I'd just like to de-clutter the property window.

  • Alex F
    Alex F about 15 years
    Thanks, Browsable took care of it for me.
  • Jeff Yates
    Jeff Yates about 15 years
    No problem. Always happy to help.