Common Event Handler For All Objects On a Form

BMS5819
06-17-2004, 07:57 AM
I’m trying to write a common event handler for all objects on a form. It’s easy enough to create something like the following, where I can get the actual name of the object that fired the event:

--------------------------------------------------------------------------
Private Sub All_CheckBox(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged, CheckBox2.CheckedChanged

MessageBox.Show("Event Caused By=" & CType(CType(sender, System.Windows.Forms.CheckBox).Name, String))

End Sub
--------------------------------------------------------------------------

What I can’t figure out is how to replace the hardcoded “System.Windows.Forms.CheckBox” with something like “Ctype(sender,blah-blah-blah)” so that this same event handler would handle events from other object types [a button, etc].

Can someone help ?

Thanks !

Iceplug
06-17-2004, 11:26 AM
Perhaps you can try CTyping it to a System.Windows.Forms.Control.
In addition, you can use the TypeOf operator to get the type of the control, and perform the event accordingly... watch out for event procedures that take a different set of eventargs though. :)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum