inherited forms control events

adshocker

Well-known member
Joined
Jun 30, 2007
Messages
180
Programming Experience
Beginner
hi all,

i just recently upgraded to VS 2005 and i'm having some problems.
i create a base form library class with a toolstrip and menustrip on it. i set their modifiers to protected (also tried public) but when i add the inherited form to my windowsapplication, i cant activate their event. basically i cant get to their event. in vb.net 2003 i simply double-click the control on the inherited form and it will be bring my right to its event procedure. this step doesnt seem to work in vb 2005.

can someone help?

thanks.
 
If I understand your problem well, it is because the form in which you handle the event using the "handles" keyword must possess a reference to the object that throws the event. A reference in the superclass won't do it.

This is all because, behing the scenes, the instance variable that represents the reference to the object throwing the event is replaced by a property such that you may set is without having to register the event handlers again.

I see 2 possibilities to obtain the behavior you are seeking :

You may either use dynamic event handling using the addhandler/removehandler keywords. If you will never change these controls, simply add the lines "addhandler controlName.eventName, addressof methodname" for each event in the form_load event handler.

You may rethrow the event form the super class and catch it in the sub class to do the actions you wish. Do this either by adding an event to the super class or by calling a method in the super class and overriding its behavior in the sub class.
 
Back
Top