Hi F.Xaver,
From my point of view it could work with a mixture.
I create TxtA(i) and give each textbox a .Name TxtA_1, TxtA_2 ...
Filling the textbox array could be done by TxtA(i).Text = ...
But getting textbox input could be realized by the textbox.Name TxtA_1 ...
This works with the following code.
Is this good practice?
Option Explicit On
Option Strict On
Option Infer Off
Public Class Form1
Dim TxtA(10) As System.Windows.Forms.TextBox
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim y As Integer = 20
Dim i As Integer = 0
For i = 0 To 9
TxtA(i) = New System.Windows.Forms.TextBox
Me.Controls.Add(TxtA(i))
With TxtA(i)
.Location = New System.Drawing.Point(360, y)
.Name = "TxtA_" + i.ToString()
.Size = New System.Drawing.Size(100, 20)
.Visible = True
End With
y += 25
Next i
For Each tb As TextBox In Me.Controls
AddHandler tb.KeyPress, AddressOf TA_KeyPress
AddHandler tb.GotFocus, AddressOf TA_GotFocus
AddHandler tb.LostFocus, AddressOf TA_LostFocus
Next
TxtA(0).Text = "000"
TxtA(1).Text = "1111"
End Sub
Private Sub TA_KeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs)
Dim MyTextBox As TextBox = DirectCast(sender, TextBox)
MessageBox.Show(String.Format("TextBox where Key was Pressed {0} Containing String {1} Actual Char {2}", MyTextBox.Name, MyTextBox.Text, e.KeyChar.ToString()))
End Sub
Private Sub TA_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs)
Dim MyTextBox As TextBox = DirectCast(sender, TextBox)
MyTextBox.BackColor = Color.LightBlue
End Sub
Private Sub TA_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs)
Dim MyTextBox As TextBox = DirectCast(sender, TextBox)
MyTextBox.BackColor = Color.Yellow
End Sub
End Class