2

First, thank you for taking the time to read my question.

I have spent a good amount of time on this issue with no success. I have created a Custom TextBox which inherits from TextBox. The Custom TextBox provides a more advanced suggestion drop-down menu with better filtering. The custom TextBox works beautifully, but I would like to hide the properties related to the original suggestion menu from the Properties Window in Visual Studio:

  • AutoCompleteCustomSource
  • AutoCompleteMode
  • AutoCompleteSource

The code I've developed to try and hide these properties is:

    [ReadOnly(true)]
    [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
    [Obsolete("This property is obsolete.", true)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
    new private AutoCompleteStringCollection AutoCompleteCustomSource { get; set; }

    [ReadOnly(true)]
    [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
    [Obsolete("This property is obsolete.", true)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
    new private AutoCompleteMode AutoCompleteMode { get; set; }

    [ReadOnly(true)]
    [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
    [Obsolete("This property is obsolete.", true)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
    new private AutoCompleteSource AutoCompleteSource { get; set; }

The sources I've used are:

The properties are still being displayed. Please provide a working example or a reference to one.

Thank you again for lending me your time.

Community
  • 1
  • 1

1 Answers1

0

In your actual code, do you really use the new keyword to allow your declared properties to hide base class properties?

If so, then it seems most likely to me that the properties being shown in the VS Designer are not your own, but rather the base class properties.

Note that this only happens when you also change the accessibility of the property (e.g. where the base class property is public but your own derived class property is private).

Just one more example of why it's almost always wrong to hide inherited members.

Peter Duniho
  • 68,759
  • 7
  • 102
  • 136
  • I am hiding the base class properties to prevent confusion with the advanced properties of my suggestion drop-down menu. The issue was resolved by changing private to public. Thank you for your reply. – Paul - Soura Tech LLC Oct 30 '14 at 16:56
  • Correct. As I wrote in my answer: "Note that this only happens when you also change the accessibility of the property". If you fix the accessibility so that it remains "public" as in the base class, you get the behavior you want. I actually made that point in my answer...I guess you just didn't notice. – Peter Duniho Oct 30 '14 at 17:07
  • You said: "In your actual code, do you really use the new keyword to allow your declared properties to hide base class properties? If so, then it seems most likely to me that the properties being shown in the VS Designer are not your own, but rather the base class properties." I was answering your question. I'm competent enough to "notice" you answer. And I disagree with your comment: "Just one more example of why it's almost always wrong to hide inherited members." But this isn't a discussion forum. – Paul - Soura Tech LLC Oct 31 '14 at 18:39