How to hide an inherited property. |
|
Author |
Message |
shimoni

|
Posted: Sat Jun 30 09:35:24 CDT 2007 |
Top |
Visual Basic [VB] >> 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
Visual Studio312
|
|
|
|
 |
Mattias

|
Posted: Sat Jun 30 09:35:24 CDT 2007 |
Top |
Visual Basic [VB] >> 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.
Then inheritance probably isn't the right approach to take. Maybe your
control should contain a Panel instead?
Mattias
--
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
|
|
|
|
 |
active

|
Posted: Sat Jun 30 09:59:47 CDT 2007 |
Top |
Visual Basic [VB] >> How to hide an inherited property.
That would not work, I need inheritance, but I want to remove one property
because I set it in my control.
thanks
> >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
>
> --
> http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
> Please reply only to the newsgroup.
|
|
|
|
 |
AlexS

|
Posted: Sat Jun 30 10:02:21 CDT 2007 |
Top |
Visual Basic [VB] >> How to hide an inherited property.
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.
> >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
>
> --
> http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
> Please reply only to the newsgroup.
|
|
|
|
 |
Joergen

|
Posted: Sat Jun 30 11:53:14 CDT 2007 |
Top |
Visual Basic [VB] >> How to hide an inherited property.
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"
>That would not work, I need inheritance, but I want to remove one property
>because I set it in my control.
>
>thanks
>
>
>> >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
>>
>> --
>> http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
>> Please reply only to the newsgroup.
>
|
|
|
|
 |
active

|
Posted: Sat Jun 30 12:32:02 CDT 2007 |
Top |
Visual Basic [VB] >> How to hide an inherited property.
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?
>
> 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"
>
>>That would not work, I need inheritance, but I want to remove one property
>>because I set it in my control.
>>
>>thanks
>>
>>
>>> >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
>>>
>>> --
>>> http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
>>> Please reply only to the newsgroup.
>>
>
|
|
|
|
 |
active

|
Posted: Sat Jun 30 12:34:05 CDT 2007 |
Top |
Visual Basic [VB] >> How to hide an inherited property.
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?
> >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
>
> --
> http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
> Please reply only to the newsgroup.
|
|
|
|
 |
Joergen

|
Posted: Sat Jun 30 13:04:56 CDT 2007 |
Top |
Visual Basic [VB] >> How to hide an inherited property.
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"
>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?
>
>
>>
>> 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"
>>
>>>That would not work, I need inheritance, but I want to remove one property
>>>because I set it in my control.
>>>
>>>thanks
>>>
>>>
>>>> >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
>>>>
>>>> --
>>>> http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
>>>> Please reply only to the newsgroup.
>>>
>>
>
|
|
|
|
 |
active

|
Posted: Sat Jun 30 14:42:59 CDT 2007 |
Top |
Visual Basic [VB] >> How to hide an inherited property.
That's what I did except for the attributes. I'm not sure if they buy
anything.
Thanks a lot
>
> 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"
>
>>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?
>>
>>
>>>
>>> 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"
>>>
>>>>That would not work, I need inheritance, but I want to remove one
>>>>property
>>>>because I set it in my control.
>>>>
>>>>thanks
>>>>
>>>>
>>>>> >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
>>>>>
>>>>> --
>>>>> http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
>>>>> Please reply only to the newsgroup.
>>>>
>>>
>>
>
|
|
|
|
 |
|
|