Inheritance

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

HI guys,

I am developing an application using c# sharp.I have a base form and all
other forms inherits from the base form.

all was running so well until i was given the task to find out which
inherited form is actually being used.

i.e i have a button in my base form and on clicking that button i want to
know which child is accessing the base form currently..

Please if this is possible then let me know ....

Lots of thanks in advance.
 
If this is inheritance, then you should just be able to call GetType(); this
should return the type of the derived class, not the base class.

Does this suffice?

Marc
 
You're not being really clear about what you would like to do. Inherritance
is more of a design time property. When the forms are generated at run-time,
their properties are inherrited by the parent object. If you are trying to
see if the children are properly connected to the base form try

ChildForm.Parent.Name

This will give you the name of the parent of the child form.
 
As another posted said you can use this.GetType() to find out the
instantiated type. However, I would be very wary of any behavior that
depended on this type of setup as it sounds like it'll be a
maintenance hassle down the road and certainly be very confusing.

If you need the child forms to do somethign special then create a
virtual method, for example:


private void closeButton_Click(object sender, EventArgs e) {
OnBeforeCloseClick();
.. do something
OnAfterCloseClick();
}

protected virtual void OnBeforeCloseClick() {
// for extension
}

proteced virtual void OnAfterCloseClick() {
// for extension
}

HTH,

Sam
 
The Parent property is related to the composition relationship between
controls--which form or control contains the target control. There is
no correlation between the Parent property and the inheritance chain.

Inherittance is used at both design and runtime and it crucial to how
..NET works, especially forms and controls.

Sam


------------------------------------------------------------
We're hiring! B-Line Medical is seeking Mid/Sr. .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.



On Wed, 22 Nov 2006 03:47:01 -0800, Andrew McNab <Andrew
 
Yes, as Neff says. I think it would be better to put the special
implementation in the derived class. That is what it is for, afterall, and
the base class can't really be aware of all future possible derived classes
as that would make the encapsilation a bit hairy.
 
Back
Top