我是编程新手。我正在学习视觉基础。我正在使用visual basic 2008,我需要以下代码的帮助:
Private Sub Timer1_Tick(ByVal sender As System.Object....
Dim i As New Integer
Dim nrnote As New Integer
nrnote = TextBoxnrnote.Text
For i = 1 To nrnote
TextBox.i.Show()
Next
Timer1.Stop()
以上代码导致以下错误:
'i'不是'System.Windows.Forms.TextBox'的成员。
nrnote
是应显示的最大文本框数。例如,如果我输入nrnote = 5
,则表单上将显示文本框1,2,3,4和5。
答案 0 :(得分:1)
如果一致地命名(例如TextBox1
,TextBox2
,TextBox3
),那么你可以这样做:
For i As Integer = 1 To nrnote
Dim t As TextBox = CType(Me.Controls("TextBox" & i.ToString()), TextBox)
t.Visible = True
Next
否则,您可以将文本框添加到数组中,如下所示:
Dim textBoxes() As TextBox = { FirstTextBox, SecondTextBox, ThirdTextBox }
For i As Integer = 1 To nrnote
textBoxes(i).Visible = True
Next