I have this "template" form which is based on System.Windows.Forms.Form. I
created a new form(the derived form) which inherits this form.

I have observed that if, at runtime, I run through all of the controls in
the controls collection of the "template" form, I can have access to all the
controls that exist in the derived form! Now this seems odd to me; why should
a base class have the controls of a class above it (the derived form), in its
controls collection.

Certainly I would expect the class derived from the template to see all the
controls on the base class but not the other way around.


--
Michael Hockstein

Re: Inheritance in forms which inherit template forms by joeycalisay

joeycalisay
Sun Jan 02 23:02:16 CST 2005

> why should
> a base class have the controls of a class above it (the derived form), in
its
> controls collection.

Technically, child classes are DOWN not up/above the hierarchy. Anyway, the
CONTROLS (Control Collection) property of the form is declared as public and
is therefore inherited down the hierarchy tree. Custom controls added in
your child forms are also added to this inherited property and if you are
debugging after the child class was instantiated and the Controls in it are
added (usually in InitializeComponent method), you will normally see them.
Your base form, child form all share the same Controls collection which is
defined in System.Windows.Forms.Control class which is a base class of
System.Windows.Forms.Form



Re: Inheritance in forms which inherit template forms by howlinghound

howlinghound
Mon Jan 03 10:03:03 CST 2005

Child classes are down! I always goof up this one!

So even though a control is placed on a child class, it will be added to the
Controls collection higher up in the inheritance chain. The child class
doesn't have it's own Controls collection, it uses the inherited one.

Unlike a control, if I create some other object local to a child class,
which is not stored in a "collection" in a higher base class, this local
object will not be visible to base classes.

Got it! Thanks for your help.

Michael

"joeycalisay" wrote:

> > why should
> > a base class have the controls of a class above it (the derived form), in
> its
> > controls collection.
>
> Technically, child classes are DOWN not up/above the hierarchy. Anyway, the
> CONTROLS (Control Collection) property of the form is declared as public and
> is therefore inherited down the hierarchy tree. Custom controls added in
> your child forms are also added to this inherited property and if you are
> debugging after the child class was instantiated and the Controls in it are
> added (usually in InitializeComponent method), you will normally see them.
> Your base form, child form all share the same Controls collection which is
> defined in System.Windows.Forms.Control class which is a base class of
> System.Windows.Forms.Form
>
>
>