Click here to Skip to main content
15,921,660 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I've a 10x10 matrix of buttons. I need to create a common button click event handler. How can I do that?

Thanx
Posted

VB
Private Sub Button_Click(sender as object, e as ButtonClickEventArgs) Handles, Button1.Click, Button2.Click, etc...
  Dim btn as Button = DirectCast(sender, Button)
  Select Case btn.Name
    Case "Button1"
      do something
    Case "Button2"
      do something else
    Etc...
  End Select
End Sub


Or:

VB
Private Sub test()
    For Each c As Control In Me.Controls
        If c.GetType.ToString = "Button" Then
            AddHandler c.Click, AddressOf Button_Click
        End If
    Next
End Sub
 
Share this answer
 
v2
Comments
DEB4u 10-Sep-11 18:32pm    
Private Sub Button_Click(sender as object, e as ButtonClickEventArgs) Handles, Button1.Click, Button2.Click, etc...

This thing is not working as the buttons are created dynamically.
Hmm seems I just answered your repost, please don't repost your question.
event handler for dynamically created buttons[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900