Public Class Form1
Private boxes(100) As TextBox
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
For i = 0 To 9
For j = 0 To 9
Dim newCtrl As TextBox = New TextBox
newCtrl.Size = New Drawing.Size(50, 50)
newCtrl.Location = New Point(10 + 50 * j, 10 + 50 * i)
newCtrl.Text = i * 10 + j
AddHandler newCtrl.Click, AddressOf TextBox_clicked
boxes(i) = newCtrl
Me.Controls.Add(newCtrl)
Next
Next
End Sub
Private Sub TextBox_clicked(sender As System.Object, e As System.EventArgs)
Dim box As TextBox = DirectCast(sender, TextBox)
MsgBox("You clicked the box containing " & box.Text)
End Sub
End Class