[ACCEPTED]-Hiding unwanted properties in custom controls-gdi+

Accepted answer
Score: 29

From code, the closest you can do it to 5 hide it, and perhaps make it a pain to call 4 directly - note that even when hidden it 3 is callable, and none of this will work 2 past a cast:

// about the closest you can do, but not really an answer
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("just cast me to avoid all this hiding...", true)]
public new ContentAlignment TextAlign { get; set; }

Personally, I wouldn't bother. It 1 isn't robust (just cast).

Score: 3

You can use the [EditorBrowsable] attribute, as documented here.

public bool HideMeInIntellisense
    // ...

From the 12 documentation:

...the IntelliSense engine 11 in Visual Studio uses this attribute to 10 determine whether to show a property or 9 method.

However, users can override this 8 in VS settings. ReSharper also has a setting 7 that controls whether this attribute is 6 honoured in its IntelliSense.

Out of curiousity, why 5 do you want to hide something from users? Just 4 because a member is hidden in the way described 3 above doesn't mean you couldn't use it in 2 code and compile it successfully. It just 1 inhibits the discoverability of the member.

Score: 1

Maybe what you want to do is derive from 3 ContainerControl or UserControl, add a Button 2 to that control and just expose those parts 1 of the Button interface you want to keep.

Score: 1

No, you can remove them from the designer 4 (as shown) but you cannot really hide them 3 form code as that would violate the substitution 2 principle. It has been asked & answered 1 many times here, see for example this SO question.

Score: 0

Why don't you make it private? It guarantees 4 that ancestors will not see it. Edit: In 3 this case you have to inherit a new class 2 from the base and use your new class, which 1 now hides ths property.

public class MyTextBox: TextBox
        private new ContentAlignment TextAlign
          get { return base.ContentAlignment; }
          set { base.ContentAlignment = value; }

More Related questions