我有这三个图像,我已经绘制到我的表格中。
GraphicsBuffer.DrawImage(ButtonEasy, New Rectangle(25, 330, 100, 50), 0, 0, 100, 50, GraphicsUnit.Pixel, ImageAttributes)
GraphicsBuffer.DrawImage(ButtonMedium, New Rectangle(150, 330, 100, 50), 0, 0, 100, 50, GraphicsUnit.Pixel, ImageAttributes)
GraphicsBuffer.DrawImage(ButtonHard, New Rectangle(275, 330, 100, 50), 0, 0, 100, 50, GraphicsUnit.Pixel, ImageAttributes)
但是我想为它们被单击时创建一个布尔表达式,以便我可以触发事件以加载所选的游戏模式。
我是通过资源代码执行此操作还是有一种简单的方法可以执行此操作。我的想法似乎很糟糕而且语法不正确。
编辑:我已经做到了:
Private Sub ButtonEasy_MouseClick(ByVal sender As Object, ByVal e As MouseEventArgs) _
Handles ButtonEasy.MouseClick
Dim buttonEasyRect = New Rectangle(25, 330, 100, 50)
If buttonEasyRect.Contains(e.Location) Then
End If
End Sub
但不确定从哪里开始。显然“ButtonEasy.Mouseclick”句柄会引发错误“WithEvents variable undefined”。不知道从这里去哪里。
提前致谢!
Edit2:在 LarsTech 的帮助下,我得到了一个枚举,并且这个:
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles Me.MouseDown
Dim level As Difficulty = Difficulty.None
If e.Button = MouseButtons.Left Then
End If
If New Rectangle(25, 330, 100, 50).Contains(e.Location) Then
level = Difficulty.Easy
ElseIf New Rectangle(150, 330, 100, 50).Contains(e.Location) Then
level = Difficulty.Medium
ElseIf New Rectangle(275, 330, 100, 50).Contains(e.Location) Then
level = Difficulty.Hard
End If
If level = Difficulty.Easy Then
GameMode = 1
ElseIf level = Difficulty.Medium Then
GameMode = 2
ElseIf level = Difficulty.Hard Then
GameMode = 3
End If
End Sub
我如何在我的循环中调用它?目前我有循环等待 Asynchkeypress 将时间刻度设置为 300 以启动游戏。