470,573 Members | 1,668 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,573 developers. It's quick & easy.

Disable items from an inherited class?

Hi All
I have a custom class that is derived from the PictureBox class. One of the
properties from the PictureBox class is "SizeMode" and in my custom class I
want to disable the user from being able to modify this.

How can I remove this property from my class?

Thanks,
Steve

Apr 26 '07 #1
8 1770

"Steven Garrad" <st******@hot-nospam-mail.comwrote in message
news:08**********************************@microsof t.com...
Hi All
I have a custom class that is derived from the PictureBox class. One of
the properties from the PictureBox class is "SizeMode" and in my custom
class I want to disable the user from being able to modify this.

How can I remove this property from my class?

Thanks,
Steve
One possibility is override.

http://msdn2.microsoft.com/en-us/lib...h3(VS.71).aspx
Apr 26 '07 #2
I've tried to override this, but SizeMode does not appear.

"pvdg42" <pv****@newsgroups.nospamwrote in message
news:#Q*************@TK2MSFTNGP05.phx.gbl...
>
"Steven Garrad" <st******@hot-nospam-mail.comwrote in message
news:08**********************************@microsof t.com...
>Hi All
I have a custom class that is derived from the PictureBox class. One of
the properties from the PictureBox class is "SizeMode" and in my custom
class I want to disable the user from being able to modify this.

How can I remove this property from my class?

Thanks,
Steve

One possibility is override.

http://msdn2.microsoft.com/en-us/lib...h3(VS.71).aspx

Apr 26 '07 #3
Hi,

"pvdg42" <pv****@newsgroups.nospamwrote in message
news:%2***************@TK2MSFTNGP05.phx.gbl...
>
"Steven Garrad" <st******@hot-nospam-mail.comwrote in message
news:08**********************************@microsof t.com...
>Hi All
I have a custom class that is derived from the PictureBox class. One of
the properties from the PictureBox class is "SizeMode" and in my custom
class I want to disable the user from being able to modify this.

How can I remove this property from my class?
SizeMode is not virtual , so you cannot override it
Apr 26 '07 #4
Hi,

"Steven Garrad" <st******@hot-nospam-mail.comwrote in message
news:08**********************************@microsof t.com...
Hi All
I have a custom class that is derived from the PictureBox class. One of
the properties from the PictureBox class is "SizeMode" and in my custom
class I want to disable the user from being able to modify this.

How can I remove this property from my class?
you have to use the "new" keyword to hide the parent implementation:

new public XXXX SizeMode{
I do not remmber that SizeMode returns that's why the XXXX
Apr 26 '07 #5
AJ
In article <eg**************@TK2MSFTNGP04.phx.gbl>, "Ignacio Machin
\( .NET/ C# MVP \)" <machin TA laceupsolutions.comsays...
Hi,

"Steven Garrad" <st******@hot-nospam-mail.comwrote in message
news:08**********************************@microsof t.com...
Hi All
I have a custom class that is derived from the PictureBox class. One of
the properties from the PictureBox class is "SizeMode" and in my custom
class I want to disable the user from being able to modify this.

How can I remove this property from my class?

you have to use the "new" keyword to hide the parent implementation:

new public XXXX SizeMode{
I do not remmber that SizeMode returns that's why the XXXX
... though there's nothing to stop a user casting your class to a
PictureBox, and using the original SizeMode property.

The only way to completely hide it is to encapsulate a PictureBox
internally, rather than deriving from it.
Apr 26 '07 #6
Steven Garrad <st******@hot-nospam-mail.comwrote:
I have a custom class that is derived from the PictureBox class. One of the
properties from the PictureBox class is "SizeMode" and in my custom class I
want to disable the user from being able to modify this.

How can I remove this property from my class?
Doing so would break Liskov's Substitutability Principle. Basically, if
you don't want type X to have all of the same members available as type
Y, you shouldn't derive type X from type Y in the first place.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 26 '07 #7
It's not that I don't want it, but it's that I don't want it to be changed
by the user of the control.
"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:MP******************@msnews.microsoft.com...
Steven Garrad <st******@hot-nospam-mail.comwrote:
>I have a custom class that is derived from the PictureBox class. One of
the
properties from the PictureBox class is "SizeMode" and in my custom class
I
want to disable the user from being able to modify this.

How can I remove this property from my class?

Doing so would break Liskov's Substitutability Principle. Basically, if
you don't want type X to have all of the same members available as type
Y, you shouldn't derive type X from type Y in the first place.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 26 '07 #8
Steven Garrad <st******@hot-nospam-mail.comwrote:
It's not that I don't want it, but it's that I don't want it to be changed
by the user of the control.
That's the same thing, effectively. You want to stop the user from
treating the control as if it were a normal PictureBox, which is what
Liskov's principle is about.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 26 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by jwsacksteder | last post: by
5 posts views Thread by Bob Bedford | last post: by
reply views Thread by Ian | last post: by
1 post views Thread by Geroge D. Lake | last post: by
7 posts views Thread by OpticTygre | last post: by
1 post views Thread by =?Utf-8?B?QW5kcmV3?= | last post: by
5 posts views Thread by Kevinp | last post: by
1 post views Thread by livre | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.