Phylum Posted July 10, 2003 Posted July 10, 2003 Is it possible to have a handles clause that handles every control? For instance: Private SUB Btn1_Click(BLAH) Handles BUTTON1 (Syntax may be incorrect) What I want is an event handler that handles every button on the form Private SUB Bnt1_Click(BLAH) Handles all buttons WITHOUT Listing every control in the handles clause. Possible? Quote
*Experts* mutant Posted July 10, 2003 *Experts* Posted July 10, 2003 You can have something like this: Dim btn As Control For Each btn In Me.Controls If TypeOf btn Is Button Then AddHandler btn.Click, Addressof handlingsub end if Next Quote
Leaders dynamic_sysop Posted July 10, 2003 Leaders Posted July 10, 2003 as mutant said you can add a handler , by going through the buttons in your control collection , here's a quick example , if you add a few buttons , the handler will still know which button was clicked as you would see in the messagebox . Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim btn As Control For Each btn In Controls If TypeOf btn Is Button Then AddHandler btn.Click, AddressOf ClickEvent End If Next End Sub Private Sub ClickEvent(ByVal sender As System.Object, ByVal e As System.EventArgs) MessageBox.Show("i'm a click from " & sender.name) End Sub Quote
Phylum Posted July 10, 2003 Author Posted July 10, 2003 Thanks alot for the help guys. Very fast response, you rock! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.