Event Handle vs. Sub Procedure

Denaes

Well-known member
Joined
Jun 10, 2003
Messages
956
I found out a cool way to modify a procedure so that you can create your own and add handles a while back after viewing some code on PlanetSourceCode.

I used this on one form of my program and honestly I cant say that I care for it.

Its a database screen were youre viewing data. When the form is loaded, you disable all of the textboxes so no changes can be made.

I had a procedure to do this, with the handle "MyBase.Load"

It worked and I did a few more, for the cancel, save and OK buttons.

Now Im starting to realize (after I havnt worked on this particular form for a month) that its really a bear to get everything lined up again, figuring out what went were.

I just took out all of the handles and just included calls to the sub procedures instead.

Is there one way thats better for some particular reason? Maybe one way has less overhead?

I assume its faster/easier for the program to jump directly to the handle than it is to jump to a handle and then to a sub procedure.
 
I dont know what you mean when you say "create your own". All the editor does is save you typeing it youself, this is not exactly a new find ;).

Whats the difference you say, nothing. You will never notice its such a small command, its probly 1 extra instruction and as your CPU does about 25 million a second im not sure it will care :).

In case your interested, just run to the end of the procedure line and add handles me. and you will get a list of all the controls for you to pick from and also classes that are declared globally.
You can actually do some really cool stuff, like move the handle of a control to a different procedure then the one it was defined at designed time. Heres an example.

Code:
AddHandler Application.ThreadException, AddressOf eh.OnThreadException

Also, you can use the same procedure to handle many objectes, ie same event for 2 menus, ones a normal menu, the other is a popup menu.

Code:
Private Sub mnuDeleteMenu(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mncConnRemove1.Click, mncConnRemove2.Click
 
Back
Top