你能创建一个文本框吗?将其拆分为字符串并为其分配参数。在vb.net中

时间:2015-01-23 17:12:10

标签: vb.net

我创建了一个包含大量文本框的保龄球程序。我为每个文本框指定了一个名称:TextboxF1P1T1TextboxF1P1T2TextboxF1P2T1等。

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

2 个答案:

答案 0 :(得分:0)

查看属于Controls集合的Find方法。

https://msdn.microsoft.com/en-us/library/system.windows.forms.control.controlcollection.find(v=vs.110).aspx

在表格中你可以写

Me.Controls.Find(...)

答案 1 :(得分:0)

如果控件位于groupbox引用中,则为:

Dim throw2 As Integer
Integer.TryParse(GroupBox1.Controls("TextBoxF" & frameNumber.ToString & "P" & player.ToString & "T2").Text, throw2)