Programmer XYZ
Programmer XYZ

Reputation: 408

How to see if image drawn to form through graphic.drawimage has been clicked?

 ' Show game directions.
                    ShowGameObjective()

                    ' Press any cursor key to skip instructions.
                    If ButtonEasy = True Then
                           Gamemode = 1
                    ElseIf ButtonMedium = Clicked Then

                    End If

How do I see if an Image has been directly clicked? For example: I have three images (system.drawing.bitmap) on my graphics buffer; Easy, Medium, and Hard. In the code above if ButtonEasy image is clicked, it will set the integer of Gamemode to "1", and so on depending on what image is clicked.

I think this is actually really easy to do that it isn't documented on here or msdn.

Thanks in advance!

Edit: After thinking some more, would something like this work?

Private Sub ButtonEasy_OnMouseClick ... GameMode=1 End Sub

Upvotes: 0

Views: 215

Answers (2)

Olivier Jacot-Descombes
Olivier Jacot-Descombes

Reputation: 112712

In the MouseClick event handler you can do something like:

Dim buttonRect = New Rectangle(50, 20, 100, 100)
If buttonRect.Contains(e.Location) Then ...

Upvotes: 1

SLaks
SLaks

Reputation: 888087

Handle the MouseClick event and check where e.Location is.

Upvotes: 1

Related Questions