PC Review


Reply
Thread Tools Rate Thread

Disable items from an inherited class?

 
 
Steven Garrad
Guest
Posts: n/a
 
      26th Apr 2007
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

 
Reply With Quote
 
 
 
 
pvdg42
Guest
Posts: n/a
 
      26th Apr 2007

"Steven Garrad" <(E-Mail Removed)> wrote in message
news:087B334B-5D1C-4688-8FDF-(E-Mail Removed)...
> 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/library/ebca9ah3(VS.71).aspx


 
Reply With Quote
 
Steven Garrad
Guest
Posts: n/a
 
      26th Apr 2007
I've tried to override this, but SizeMode does not appear.

"pvdg42" <(E-Mail Removed)> wrote in message
news:#(E-Mail Removed)...
>
> "Steven Garrad" <(E-Mail Removed)> wrote in message
> news:087B334B-5D1C-4688-8FDF-(E-Mail Removed)...
>> 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/library/ebca9ah3(VS.71).aspx
>
>

 
Reply With Quote
 
Ignacio Machin \( .NET/ C# MVP \)
Guest
Posts: n/a
 
      26th Apr 2007
Hi,

"pvdg42" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
>
> "Steven Garrad" <(E-Mail Removed)> wrote in message
> news:087B334B-5D1C-4688-8FDF-(E-Mail Removed)...
>> 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


 
Reply With Quote
 
Ignacio Machin \( .NET/ C# MVP \)
Guest
Posts: n/a
 
      26th Apr 2007
Hi,

"Steven Garrad" <(E-Mail Removed)> wrote in message
news:087B334B-5D1C-4688-8FDF-(E-Mail Removed)...
> 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


 
Reply With Quote
 
AJ
Guest
Posts: n/a
 
      26th Apr 2007
In article <(E-Mail Removed)>, "Ignacio Machin
\( .NET/ C# MVP \)" <machin TA laceupsolutions.com> says...
> Hi,
>
> "Steven Garrad" <(E-Mail Removed)> wrote in message
> news:087B334B-5D1C-4688-8FDF-(E-Mail Removed)...
> > 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.
 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      26th Apr 2007
Steven Garrad <(E-Mail Removed)> wrote:
> 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 - <(E-Mail Removed)>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
Steven Garrad
Guest
Posts: n/a
 
      26th Apr 2007
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]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Steven Garrad <(E-Mail Removed)> wrote:
>> 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 - <(E-Mail Removed)>
> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
> If replying to the group, please do not mail me too


 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      26th Apr 2007
Steven Garrad <(E-Mail Removed)> wrote:
> 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 - <(E-Mail Removed)>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Instance of derived class does not show public methods or properties that are not in the inherited class D Witherspoon Microsoft Dot NET 5 28th Mar 2006 11:25 PM
Instance of derived class does not show public methods or properties that are not in the inherited class D Witherspoon Microsoft VB .NET 5 28th Mar 2006 11:25 PM
Why I can't create a contructor in a class inherited from Component Model class C.G. Oh Microsoft Dot NET Framework 0 19th Nov 2004 02:09 PM
access from one inherited to the other inherited class newbie_csharp Microsoft C# .NET 6 26th Oct 2004 03:45 PM
implementing inherited control re:Ken Tucker - Inherited DataGrid Class Doug Bell Microsoft VB .NET 2 6th Oct 2004 10:07 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:42 AM.