I'm new to custom classes. I have a class called 'game'. In the class, I have a method called 'addGame()' that creates a dynamic picture box called 'pBox'. After creating the control, I'm doing the following to register a click event:
AddHandler pBox.Click, AddressOf Me.launchGame
And here is launchGame:
Public Sub launchGame()
MsgBox(Me.name)
End Sub
The problem is, "Me.name" is always the most recently added instances name, not the one I clicked on.
Based on a suggestion, I also tried this:
Public Sub launchGame(ByVal sender As Object)
MsgBox(sender.name)
End Sub
But now "AddHandler pBox.Click, AddressOf Me.launchGame" says
Method 'Public Sub launchGame(sender As Object)' does not have a signature compatible with delegate 'Delegate Sub EventHandler(sender As Object, e As System.EventArgs)'
And "AddHandler pBox.Click, AddressOf Me.launchGame(Me)" says
AddressOf operand must be the name of a method without parentheses
Public Sub launchGame(ByVal sender As Object, ByVal sender as EventArgs)
MsgBox(sender.name)
End Sub
Now no errors, but the msgBox is blank.