Hide property in inherited class? 
Author Message
 Hide property in inherited class?

Hi all,

I would like to know whether it is possible to hide (make
invisible) property in a custom control which inherits
from existing Windows Forms Controls?

For example, my control inherits TextBox control and I
don't want the application (which consumes my control)
accesses (both read and write) property BackColor".

I've tried to use <System.ComponentModel.Browsable(False)

Quote:
> but it doesn't work fine.  Though this property is

invisible in property window, it still can be accessed in
code segment.

Thanks for your attention and help!

James Wong



Sat, 30 Apr 2005 17:45:21 GMT  
 Hide property in inherited class?
No, because that would break the concept of inheritence.
If you want to create a new type of thing, write a wrapper.
If you want to create something that is 'a type of' another thing you use
inheritence, and this means you can't remove public methods, only alter
their implementation or return values.  If you allowed the removal of
methods, you could never refer to a derived class object via the base class
interface, because methods would be missing and the interface broken.

Cheers,
  Jason


Quote:
> Hi all,

> I would like to know whether it is possible to hide (make
> invisible) property in a custom control which inherits
> from existing Windows Forms Controls?

> For example, my control inherits TextBox control and I
> don't want the application (which consumes my control)
> accesses (both read and write) property BackColor".

> I've tried to use <System.ComponentModel.Browsable(False)
> > but it doesn't work fine.  Though this property is
> invisible in property window, it still can be accessed in
> code segment.

> Thanks for your attention and help!

> James Wong



Sat, 30 Apr 2005 19:44:52 GMT  
 Hide property in inherited class?
    Hi,

        that is the opposite of then meaning of inheritance.
        If you have a class that inherits from TextBox you are telling that
anyone can treat this object as a TextBox, what implies that it has the same
(at least) properties and the same methods. (It is, it implements the same
interface)

        Al you can do is override the BackColor property and make this one
to don't do anything, or throw an Illegal Operation Exception (or whatever)

        public Overrides Property BackColor() As System.Drawing.Color

    Hope this helps,

                Luis R.C.



Quote:
> Hi all,

> I would like to know whether it is possible to hide (make
> invisible) property in a custom control which inherits
> from existing Windows Forms Controls?

> For example, my control inherits TextBox control and I
> don't want the application (which consumes my control)
> accesses (both read and write) property BackColor".

> I've tried to use <System.ComponentModel.Browsable(False)
> > but it doesn't work fine.  Though this property is
> invisible in property window, it still can be accessed in
> code segment.

> Thanks for your attention and help!

> James Wong



Sat, 30 Apr 2005 19:03:55 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Hiding methods in inherited classes

2. Can you hide properties of inherited collection?

3. Identifying Inherited Classes Properties and Methods seperately form inheriting classes P's and M's

4. Problem with a vb.Net class inheriting from a c# class

5. nested class inherits containing class accessing private instance members

6. Hiding Properties in a Derived Class?

7. Masking Inherited Properties in a property grid

8. How to hide method or property in inherited class?

9. Hiding Inherited methods

10. hiding inherited methods

11. DataGrid remove item error bind with own class inherit from collection

12. DataGrid remove item error bind with own class inherit from collection

 

 
Powered by phpBB® Forum Software