Newbie question about visual inheritance

  • Thread starter Thread starter Still Love VB6
  • Start date Start date
S

Still Love VB6

Hi All

VB.Net 2005 - Pro

Sorry if this question has been asked before. I have Googled and did not
find a simple explanation.

I have a form in a seperate class library (yeah, I did read that bit) called
frmTemplate which contains four buttons (Close, Save, New, Delete)

When I inherit this form into my project, these buttons are all locked, so
that double-clicking does not allow me to write any code for these buttons.

Have I missed something very obvious here? Is there a simple explanation for
this whole visual inheritance thing? Seems like a really excellent idea, but
has me confused.

An old VBn person
 
Newbie,

If you inherit a class than all methods are in the object of that.

If you did not make them non overridable than you can override them in the
class that is using it. However thpse methods are not in the top of your
code screen, you have to use intellisence for that.

I hope this helps,

Cor
 
Inheritance is a little different than what you are used to in VB6. The
class you are inheriting is not a separate object you can catch events from.
Instead it is now a part of the class you are building. It is different than
dropping controls on a form.

When using inheritance, the derived class can override the behavior of the
base class. This is they way they work together as one. One can't fire
events to the other because they are the same object. (kinda confusing but
powerful). The advantage to this approach over VB6 is you can re-use your
base class functionality over and over again by just subclassing and
overriding what you want to do differently.

In your case, you could override your OnClick methods for each button on the
base form to achieve what you want. But, I would recommend making new
OnClose, OnSave, OnNew, and OnDelete methods in the base class. You could
call these methods in the base class whenever the Click event is received on
any of the buttons. And, you can overrride the methods with whatever code
you like in the derived class. The advatage to defining your own methods is
you could, in the future, change the underlying controls in the base class
used to trigger Close, Save, New, Delete without changing the derived
classes. For example: Make them menu items instead of buttons. (more
power!)
 
Back
Top