我有一个关于 VB.net 的问题。在此代码中,创建了 64 个按钮(通过 for 循环)。如何通过 Klik 方法和 zetnieuw 中的坐标访问按钮?因为,基本上 zetnieuw 函数只是用来制作按钮。
Public Class Form1
Dim AANTAL_KOLOMMEN As Integer = 8
Dim AANTAL_RIJEN As Integer = 8
Dim Button1 As Button
Dim tel As Boolean
Dim value1 As Integer
Dim value2 As Integer
Public Function zetNieuw(rij As Integer, kolom As Integer) As Button
Dim nieuweKnop As New Button()
nieuweKnop.Width = 40
Me.Controls.Add(nieuweKnop)
nieuweKnop.Left = kolom * nieuweKnop.Width
nieuweKnop.Top = rij * nieuweKnop.Width
nieuweKnop.Height = nieuweKnop.Width
nieuweKnop.Text = ""
AddHandler nieuweKnop.MouseDown, AddressOf Klik
...
nieuweKnop.Tag = (kolom + (rij * AANTAL_KOLOMMEN))
Return nieuweKnop
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
For Me.value1 = 1 To AANTAL_KOLOMMEN Step 1
For Me.value2 = 1 To AANTAL_RIJEN Step 1
Me.zetNieuw(value2, value1)
Next
Next
End Sub
Private Sub Klik(sender As Object, e As MouseEventArgs)
Dim knop As Button = sender
...
End Sub