0

I have a C#/WinForms application with a custom "NumericTextBox" class which inherits from TextBox. However, there are many properties in the VSDesigner that make no sense to a NumericTextBox (multiline, password chars, etc.).

Is there any way to make them "disappear" from the designer so they can't accidentally be set?

The other "solutions" on StackOverflow don't handle properties that can't be overridden.

EddieRich
  • 53
  • 1
  • 7
  • I don't believe you can make them inaccessible/non-invocable The best you can do is to use `new` keyword to provide new implementation of the property in your subclass and potentially throw an `Exception` on use. Also you can hide it in the property pages and VS intellisense using the below `Attributes` `[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]` on the property/method – Vikhram Sep 08 '17 at 14:08
  • That suggested dupe doesn't look like a match to me... – DonBoitnott Sep 08 '17 at 14:14
  • Found the answer, the solution is a [custom ControlDesigner.](https://stackoverflow.com/questions/38582461/remove-generatemember-and-modifiers-properties-in-designer) – EddieRich Sep 08 '17 at 14:21
  • Shadowing with the *new* keyword is safe in the designer, also the approach used in the framework to hide inherited properties. It is not necessarily safe in code but that ought to be easy enough to avoid. As long as you use the `base` keyword in the property getter and setter then there's nothing to worry about. – Hans Passant Sep 08 '17 at 14:40

1 Answers1

0

You can override the properties of the base class that you'd like to hide and then give them the [Browsable( false )] atttribute,

Example:

[Browsable( false )]
public new bool UseMnemonic
{
    get
    {
        return false;
    }
    set
    {
        // do nothing
    }
}
Heinz Kessler
  • 1,610
  • 11
  • 24