471,305 Members | 1,467 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,305 software developers and data experts.

Hiding inherited properties

Hi all,

How would I go about hiding an inherited property?
In particular, I want to hide the 'BackColor' property of the
UserControl class.
I will then implement my own back color related properties and
I can do all the latter, but I don't want to build this nice designable
properties and have this big ugly 'BackColor' property available to the
user of my components, which will need to be set to Transparent all the
time for my other stuff to work. I just want to hide it, make it
private or something.

I really don't want to have to build something from scratch, but IF I
did, I would start by creating a class and implementing IComponent

Many thanks,
Steven Nagy

Dec 16 '05 #1
2 1992
Well, you can't totally hide it, but you can do this:

private new Color BackColor
get { return base.BackColor; }
set { base.BackColor = value; }

The "new" will cause your newly declared "BackColor" property to "hide"
the base class's property, and since your new property is private,
nobody can see it or call it.

That said, callers can still get at the base class's BackColor property
like this:

MyFancyUserControl mine = new MyFancyUserControl();
UserControl castToBase = mine;
castToBase.BackColor = Color.Brown;

By casting to the base class UserControl, it is the base class's
BackColor property that becomes visible and will be invoked.

Now, the Designer's property grid is another question. I don't know
whether it will respect the "new" private property or not... but it's
worth a try.

Dec 16 '05 #2
Cool. Gives me somewhere to start anyways.


Dec 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by thechaosengine | last post: by
4 posts views Thread by A Ratcliffe | last post: by
4 posts views Thread by Dan | last post: by
1 post views Thread by Juan Pedro Gonzalez | last post: by
5 posts views Thread by PIEBALD | last post: by
14 posts views Thread by Dom | last post: by
9 posts views Thread by Torben Laursen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.