1

私は自分の形に描いたこれらの3つの画像を持っています。

    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」ハンドルは「WithEventsvariableundefined」というエラーをスローします。ここからどこへ行くのかわからない。

前もって感謝します!

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に設定してゲームを開始するのをループで待機しています。

4

1 に答える 1

1

これを行うために実際にボタンを使用しない理由はありますか?

いずれにせよ、おそらく、どの画像、どの四角形など、すべての情報のためのクラスが必要です。このボタン クラスは、IsPushed ロジックも保持します。

しかし、あなたが現在持っているものについては、列挙型を持つことがおそらく役立つでしょう:

Public Enum Difficulty
  None
  Easy
  Medium
  Hard
End Enum

次に、MouseDown イベントで:

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
    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
  End If

  If level <> Difficulty.None Then
    MessageBox.Show("You are playing " & level.ToString)
  End If
End Sub
于 2011-11-14T20:01:43.120 に答える