fredfrothen
New member
- Joined
- Apr 16, 2013
- Messages
- 4
- Programming Experience
- Beginner
Hey i posted the other day asking how to handle a dynamically loaded button's click event, which i got the answer of use Addhandler. I've been trying to use it for awhile but can't seem to get it to work as i need.
I've managed to capture the button click, but where i have my message box saying "Button Clicked" i need to display the caption of the button clicked, but i can't seem to add brackets to the addhandler statement.
Here's my code:
I've managed to capture the button click, but where i have my message box saying "Button Clicked" i need to display the caption of the button clicked, but i can't seem to add brackets to the addhandler statement.
Here's my code:
VB.NET:
Private Sub frmMain_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
PopulateWorlds()
End Sub
Private Sub PopulateWorlds()
Dim intCount As Integer
For intCount = 1 To 78
Dim cbDynBut As New CovButton
Me.fraRight1.Controls.Add(cbDynBut)
cbDynBut.Name = "cbWorld" & intCount
cbDynBut.Caption = "W " & intCount
cbDynBut.Width = 50
cbDynBut.Height = 16
If intCount <= 20 Then
cbDynBut.Left = 7
cbDynBut.Top = 66 + (20 * (intCount - 1))
ElseIf intCount > 20 And intCount <= 40 Then
cbDynBut.Left = 63
cbDynBut.Top = 66 + (20 * ((intCount - 1) - 20))
ElseIf intCount > 40 And intCount <= 60 Then
cbDynBut.Left = 119
cbDynBut.Top = 66 + (20 * ((intCount - 1) - 40))
Else
cbDynBut.Left = 175
cbDynBut.Top = 66 + (20 * ((intCount - 1) - 60))
End If
AddHandler cbDynBut.Click, AddressOf HandleDynButton
Next intCount
End Sub
Sub HandleDynButton()
MsgBox("Button clicked")
End Sub
Last edited: