Click here to Skip to main content
Click here to Skip to main content

Hiding inherited properties

By , 2 Oct 2011
 
When you create a custom control (or any class), you inherit a lot of properties from the base class, most of which are fine. However, particularly in the case of a control derived from UserControl, this brings a lot of properties which may not be relevant to the new control.
For example, if your control never scrolls, then the UserControl inherited property AutoScroll is confusing, and makes your control look unprofessional.
The solution is to hide them. However, actually hiding them took me quite a while to work out:
 
Create a new property with the same signature as the property you wish to hide, and give it a default getter and setter:
/// <summary>
/// Unused property
/// </summary>
[Browsable(false),
EditorBrowsable(EditorBrowsableState.Never)]
public new bool AutoScroll { get; set; }
 
The Browsable attribute tells the designer that it should not appear in the Properties window.
The EditorBrowsable attribute tells Intellisense that it should not appear in the autocomplete list.
 
When you run this, you will find that the AutoScroll property still appears in Intellisense! Annoying, isn't it? Don't worry.
It will only appear in Intellisense within your solution.
If you add a reference to your control library within an different solution, Intellisense will not list the property. (You can however still access it if you type the name in fully. Irritating, but true.)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

OriginalGriff
CEO
Wales Wales
Member
Born at an early age, he grew older. At the same time, his hair grew longer, and was tied up behind his head.
Has problems spelling the word "the".
Invented the portable cat-flap.
Currently, has not died yet. Or has he?

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionThis solution is so annoying...memberNaerling21 Jan '13 - 4:54 
GeneralMy vote of 5memberSushil Mate23 Oct '12 - 17:54 
GeneralMy vote of 5memberJörgen Andersson23 Sep '12 - 10:00 
GeneralReason for my vote of 5 nice one.membernikhi _singh1 Mar '12 - 17:53 
GeneralReason for my vote of 5 Thanks!memberbeginner201127 Sep '11 - 22:41 
GeneralReason for my vote of 5 This is very cool. Thanks!member[d3m0n]15 Mar '11 - 11:39 
GeneralReason for my vote of 5 simple and effectivememberMauxel7 Jul '10 - 3:39 
Reason for my vote of 5
simple and effective

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 2 Oct 2011
Article Copyright 2010 by OriginalGriff
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid