Vb.net 生活游戏点击拖动
我正在玩人生游戏,遇到了一个我无法解决的问题 对于游戏,我在代码中创建了一个按钮网格,我想添加一个处理程序,当鼠标按钮被单击并拖动到任何按钮上时,它会使按钮处于活动状态或死亡状态 但是我找不到任何处理程序可以帮助解决这个问题。Vb.net 生活游戏点击拖动,vb.net,conways-game-of-life,Vb.net,Conways Game Of Life,我正在玩人生游戏,遇到了一个我无法解决的问题 对于游戏,我在代码中创建了一个按钮网格,我想添加一个处理程序,当鼠标按钮被单击并拖动到任何按钮上时,它会使按钮处于活动状态或死亡状态 但是我找不到任何处理程序可以帮助解决这个问题。 这是每次创建新按钮时添加处理程序的方式: 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 te
这是每次创建新按钮时添加处理程序的方式:
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
我目前正在使用鼠标器事件,但它不能正确地配合游戏为什么拖动?用鼠标左键点击一个死掉的按钮,使其激活。左键点击一个“活着”按钮,使其死亡。@GilbertLeBlanc我相信这是因为当他将点击的鼠标移到他的细胞上时,他希望细胞变为“死/活”。@Alex:我也这么认为。不幸的是,大多数人不能用鼠标精确地绘制。通过按钮实现实际的拖放,并为所有按钮处理DragEnter()事件。您需要将所有按钮的AllowDrop()属性设置为true。