Dim txtHeight As Integer = 16
Dim txtWidth As Integer = 100
Dim txtA(txtNum - 1) As TextBox
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim er As String = ""
For i = 0 To txtNum - 1
If txtA(i).Text = "" Then
er = er & i + 1 & "."
End If
If er <> "" Then
MsgBox("第" & er & "項目沒填資料")
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim i As Integer
For i = 0 To txtNum - 1
txtA(i) = New TextBox
txtA(i).Text = ""
Me.Controls.Add(txtA(i))
txtA(i).Width = txtWidth
txtA(i).Font = New Font("新細明體", 16)
txtA(i).Left = 100
txtA(i).Top = (txtA(i).Height + 8) * i
End Sub
End Class
小改了一下你的程式
參考看看吧
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'畫面上 Button1 ,TextBox1.Text="",TextBox2.Text=2,TextBox3.Text=""
'結果 TextBox1 ,TextBox3 會彈出訊息
For Each ctl As Control In Me.Controls
If (TypeOf ctl Is TextBox) Then
Dim Txt As TextBox = DirectCast(ctl, TextBox)
If Txt.Text = "" Then
MsgBox(Txt.Name & "欄位必須填資料")
'Exit Sub
End If
End If
Next ctl
End Sub