我尝试绘制 64 个按钮(8 行 8 列)来制作游戏,但由于某种原因我的代码不起作用。我希望有人可以帮助我。
Public Class Form1
Dim AMOUNTOF_COLUMNS As Integer = 8
Dim AMOUNTOF_ROWS As Integer = 8
Public Function setNew(row As Integer, column As Integer) As Button
Dim newButton As New Button()
newButton.Width = 40
Me.Controls.Add(newButton)
newButton.Left = 0
newButton.Top = 0
newButton.Height = newButton.Width
newButton.Text = ""
newButton.Tag = (column + (row * AMOUNTOF_COLUMNS))
AddHandler newButton.MouseDown, AddressOf Klik
Return newButton
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
For value1 As Integer = 0 To AMOUNTOF_ROWS Step 1
For value2 As Integer = 0 To AMOUNTOF_COLUMNS Step 1
Me.setNew(value1, value2)
Next
Next
End Sub
如果我执行这段代码,它只会吸引我一个按钮。