我创建了一个包含大量文本框的保龄球程序。我为每个文本框指定了一个名称:TextboxF1P1T1
,TextboxF1P1T2
,TextboxF1P2T1
等。
Private Sub PlayFrame(frameNumber As Integer, player As Integer)
'This works
Dim throw1 As Integer
Integer.TryParse(TextBoxF1P1T1.Text, throw1)
'But i want something like this
Dim throw2 As Integer
Integer.TryParse("TextBoxF" & frameNumber.ToString & "P" & player.ToString & "T2.Text", throw2)
Dim frame As New Frame(1, throw1, throw2)
frame.PlayTurn()
LabelF1P1.Text = frame.TotaleScore.ToString
End Sub
答案 0 :(得分:0)
查看属于Controls集合的Find方法。
在表格中你可以写
Me.Controls.Find(...)
答案 1 :(得分:0)
如果控件位于groupbox
引用中,则为:
Dim throw2 As Integer
Integer.TryParse(GroupBox1.Controls("TextBoxF" & frameNumber.ToString & "P" & player.ToString & "T2").Text, throw2)