0

我正在制作人生游戏,但遇到了我无法解决的问题。

对于游戏,我在代码中创建了一个按钮网格,并且我想添加一个处理程序,当单击鼠标按钮并将其拖动到任何按钮上时,它会使按钮处于活动状态或死亡状态。

但我找不到任何可以帮助解决此问题的处理程序。
这就是我每次创建新按钮时添加处理程序的方式:

Dim x, y As Integer
'  Start 15 px in from left hand side of form
Dim left As Integer = 0
'  Set the size of the textbox dimensions (height and width)
Dim boxdims As Integer
'  Start 20 px from the top of the form
Dim topgap As Integer = 25
' Number of cells (horCell by VerCell)
Dim right As Integer = 15

If cboCellWorldSize.SelectedIndex = 2 Then
    boxdims = 40
    horCell = (screenWidthRes \ boxdims)
    verCell = (screenHeightRes \ boxdims)
ElseIf cboCellWorldSize.SelectedIndex = 1 Then
    boxdims = 25
    horCell = (screenWidthRes \ boxdims)
    verCell = (screenHeightRes \ boxdims)
ElseIf cboCellWorldSize.SelectedIndex = 0 Then
    boxdims = 15
    horCell = (screenWidthRes \ boxdims)
    verCell = (screenHeightRes \ boxdims)
End If

ReDim cellArray(horCell, verCell)


For x = 0 To horCell  '  Nested loop for rows and cols
    For y = 0 To verCell

        '  Create a new Button
        Dim NextButton As New Button
        '  Set some of its Properties
        With NextButton
            .Left = left
            .Height = boxdims
            .Width = boxdims
            .BackColor = dead
            .Top = topgap + (NextButton.Height * y)
            .FlatAppearance.BorderSize = 0

            AddHandler NextButton.MouseEnter, AddressOf Me.btnClick


        End With


        cellArray(x, y) = NextButton
        '  Add this new button to the Form's Controls Collection

        Me.Controls.Add(NextButton)

    Next
    '  Ready to start the next column
    '  Move the left side of the next column of textboxes
    '  over to the right.
    left += boxdims
Next

我目前正在使用 mouseEnter 事件,但它不适合游戏

4

0 回答 0