473,395 Members | 1,497 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

How to hide an inherited property.

If I create a UserControl that inherits from, say, Panel, and I do not want
my UserControl to have a property that it inherits from Panel. How can I
remove it.

For example, I might not want by control to have a BackColor property even
though it inherited that property from Panel.

Thanks
Jun 30 '07 #1
8 5840
>If I create a UserControl that inherits from, say, Panel, and I do not want
>my UserControl to have a property that it inherits from Panel. How can I
remove it.
Then inheritance probably isn't the right approach to take. Maybe your
control should contain a Panel instead?
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jun 30 '07 #2
That would not work, I need inheritance, but I want to remove one property
because I set it in my control.

thanks
"Mattias Sjögren" <ma********************@mvps.orgwrote in message
news:e9****************@TK2MSFTNGP04.phx.gbl...
If I create a UserControl that inherits from, say, Panel, and I do not
want
my UserControl to have a property that it inherits from Panel. How can I
remove it.

Then inheritance probably isn't the right approach to take. Maybe your
control should contain a Panel instead?
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Jun 30 '07 #3
Even if example maybe isn't ideal one,

private new Color BackColor {...}

doesn't hide base.BackColor. BackColor is accessible and compiles OK in
inheriting classes and external classes. Which seems to contradict
description of private and new modifiers in MSDN.

To me this looks wrong. C# 2.0.
"Mattias Sjögren" <ma********************@mvps.orgwrote in message
news:e9****************@TK2MSFTNGP04.phx.gbl...
If I create a UserControl that inherits from, say, Panel, and I do not
want
my UserControl to have a property that it inherits from Panel. How can I
remove it.

Then inheritance probably isn't the right approach to take. Maybe your
control should contain a Panel instead?
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Jun 30 '07 #4

There was a discussion about it five years ago with a very good
reply: http://tinyurl.com/2hs9f3

Basically, you can hide it from the propertygrid and from
serialization, etc, but not from someone who wants to set
it manually through code, though you could simply override
the property and ignore whatever value is set or throw an
exception if an attempt is made to set it from outside the
class.

But if your control has some kind of BackColor behavior,
why not just override the property and react sensibly and
predictably to whatever value the user sets? That would
be prettier from a component design perspective.

Regards,

Joergen Bech

On Sat, 30 Jun 2007 10:59:47 -0400, " active"
<ac**********@a-znet.comwrote:
>That would not work, I need inheritance, but I want to remove one property
because I set it in my control.

thanks
"Mattias Sjögren" <ma********************@mvps.orgwrote in message
news:e9****************@TK2MSFTNGP04.phx.gbl...
>If I create a UserControl that inherits from, say, Panel, and I do not
want
my UserControl to have a property that it inherits from Panel. How can I
remove it.

Then inheritance probably isn't the right approach to take. Maybe your
control should contain a Panel instead?
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jun 30 '07 #5
I tried this and it appears to work.

I created a Shadowed Read only Property

I haven't tested it extensively but it appears to work OK.

What do you think about that approach?
"Joergen Bech @ post1.tele.dk>" <jbech<NOSPAMNOSPAMwrote in message
news:r6********************************@4ax.com...
>
There was a discussion about it five years ago with a very good
reply: http://tinyurl.com/2hs9f3

Basically, you can hide it from the propertygrid and from
serialization, etc, but not from someone who wants to set
it manually through code, though you could simply override
the property and ignore whatever value is set or throw an
exception if an attempt is made to set it from outside the
class.

But if your control has some kind of BackColor behavior,
why not just override the property and react sensibly and
predictably to whatever value the user sets? That would
be prettier from a component design perspective.

Regards,

Joergen Bech

On Sat, 30 Jun 2007 10:59:47 -0400, " active"
<ac**********@a-znet.comwrote:
>>That would not work, I need inheritance, but I want to remove one property
because I set it in my control.

thanks
"Mattias Sjögren" <ma********************@mvps.orgwrote in message
news:e9****************@TK2MSFTNGP04.phx.gbl.. .
>>If I create a UserControl that inherits from, say, Panel, and I do not
want
my UserControl to have a property that it inherits from Panel. How can I
remove it.

Then inheritance probably isn't the right approach to take. Maybe your
control should contain a Panel instead?
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Jun 30 '07 #6
I tried this and it appears to work.

I created a Shadowed Read only Property

I haven't tested it extensively but it appears to work OK.

What do you think about that approach?

"Mattias Sjögren" <ma********************@mvps.orgwrote in message
news:e9****************@TK2MSFTNGP04.phx.gbl...
If I create a UserControl that inherits from, say, Panel, and I do not
want
my UserControl to have a property that it inherits from Panel. How can I
remove it.

Then inheritance probably isn't the right approach to take. Maybe your
control should contain a Panel instead?
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Jun 30 '07 #7

Yes, something like this:

---snip---
Public Class MyPanel
Inherits Panel

<Browsable(False),
EditorBrowsable(EditorBrowsableState.Never)_
Public Shadows ReadOnly Property BackColor() As
System.Drawing.Color
Get
Return MyBase.BackColor
End Get
End Property

End Class
---snip---

I was wrong in my first test/reply: It IS possible to
hide it from the editor using one of the attributes in
the example above. Sorry about that.

One side-effect of this is that it is hidden from the
editor within the class itself - not just inherited classes,
so you have to use MyBase.BackColor instead of
Me.BackColor to get at it.

Regards,

Joergen Bech

On Sat, 30 Jun 2007 13:32:02 -0400, " active"
<ac**********@a-znet.comwrote:
>I tried this and it appears to work.

I created a Shadowed Read only Property

I haven't tested it extensively but it appears to work OK.

What do you think about that approach?
"Joergen Bech @ post1.tele.dk>" <jbech<NOSPAMNOSPAMwrote in message
news:r6********************************@4ax.com.. .
>>
There was a discussion about it five years ago with a very good
reply: http://tinyurl.com/2hs9f3

Basically, you can hide it from the propertygrid and from
serialization, etc, but not from someone who wants to set
it manually through code, though you could simply override
the property and ignore whatever value is set or throw an
exception if an attempt is made to set it from outside the
class.

But if your control has some kind of BackColor behavior,
why not just override the property and react sensibly and
predictably to whatever value the user sets? That would
be prettier from a component design perspective.

Regards,

Joergen Bech

On Sat, 30 Jun 2007 10:59:47 -0400, " active"
<ac**********@a-znet.comwrote:
>>>That would not work, I need inheritance, but I want to remove one property
because I set it in my control.

thanks
"Mattias Sjögren" <ma********************@mvps.orgwrote in message
news:e9****************@TK2MSFTNGP04.phx.gbl. ..
If I create a UserControl that inherits from, say, Panel, and I do not
want
>my UserControl to have a property that it inherits from Panel. How can I
>remove it.

Then inheritance probably isn't the right approach to take. Maybe your
control should contain a Panel instead?
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jun 30 '07 #8
That's what I did except for the attributes. I'm not sure if they buy
anything.

Thanks a lot
"Joergen Bech @ post1.tele.dk>" <jbech<NOSPAMNOSPAMwrote in message
news:ug********************************@4ax.com...
>
Yes, something like this:

---snip---
Public Class MyPanel
Inherits Panel

<Browsable(False),
EditorBrowsable(EditorBrowsableState.Never)_
Public Shadows ReadOnly Property BackColor() As
System.Drawing.Color
Get
Return MyBase.BackColor
End Get
End Property

End Class
---snip---

I was wrong in my first test/reply: It IS possible to
hide it from the editor using one of the attributes in
the example above. Sorry about that.

One side-effect of this is that it is hidden from the
editor within the class itself - not just inherited classes,
so you have to use MyBase.BackColor instead of
Me.BackColor to get at it.

Regards,

Joergen Bech

On Sat, 30 Jun 2007 13:32:02 -0400, " active"
<ac**********@a-znet.comwrote:
>>I tried this and it appears to work.

I created a Shadowed Read only Property

I haven't tested it extensively but it appears to work OK.

What do you think about that approach?
"Joergen Bech @ post1.tele.dk>" <jbech<NOSPAMNOSPAMwrote in message
news:r6********************************@4ax.com. ..
>>>
There was a discussion about it five years ago with a very good
reply: http://tinyurl.com/2hs9f3

Basically, you can hide it from the propertygrid and from
serialization, etc, but not from someone who wants to set
it manually through code, though you could simply override
the property and ignore whatever value is set or throw an
exception if an attempt is made to set it from outside the
class.

But if your control has some kind of BackColor behavior,
why not just override the property and react sensibly and
predictably to whatever value the user sets? That would
be prettier from a component design perspective.

Regards,

Joergen Bech

On Sat, 30 Jun 2007 10:59:47 -0400, " active"
<ac**********@a-znet.comwrote:

That would not work, I need inheritance, but I want to remove one
property
because I set it in my control.

thanks
"Mattias Sjögren" <ma********************@mvps.orgwrote in message
news:e9****************@TK2MSFTNGP04.phx.gbl.. .
If I create a UserControl that inherits from, say, Panel, and I do
not
want
>>my UserControl to have a property that it inherits from Panel. How can
>>I
>>remove it.
>
Then inheritance probably isn't the right approach to take. Maybe your
control should contain a Panel instead?
>
>
Mattias
>
--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


Jun 30 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: mrVithan | last post by:
I create a user control object and show its properties through a propertygrid object in my application. It is sure that there are 100 hundred of properties inherited from...
5
by: Steve | last post by:
Visual Studio 2003 C# Windows: I have a tree view control as my main menu control down the left side of my application. This has 2 Parent Nodes on it (Jobs and Employees). beneath these 2 main...
19
by: dmiller23462 | last post by:
Hi guys....I have absolutely NO IDEA what I'm doing with Javascript but my end result is I need two text boxes to stay hidden until a particular option is selected....I've cobbled together the...
2
by: owingruters | last post by:
Hi all, I'm trying to hide a member from a base class, like so : public class class1 { public class1() { } public int i; }
6
by: Alex Sedow | last post by:
Example 1 interface I { string ToString(); } public class C : I { public void f() {
8
by: Kejpa | last post by:
Hey there! I have a tabcontrol on one of my forms. Some of the tab should not be accessable (and thus invisible) until you give the correct password. But I can't hide the tab......
12
by: Ray Cassick \(Home\) | last post by:
Ok, I have finally decided that there is ONE big thing about VB.NET (not sure if this same thing exists in C# yet) that really ticks me off. Either I am missing the point here or I have not found...
2
by: chetsjunk | last post by:
I am having problems with an inherited class not handling an event for the class it is inherited from. But it's not constistent, so I'm guessing the problem is elsewhere in my code. I created the...
4
by: asad.naeem | last post by:
hi to all this is the problem about inheritence. I have designed a form with some essential controls which are required for every form which will inherited from it. for example i have Button1 on...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.