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 !
--------------------------------------------------------------------------
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 !