0

我正在尝试创建一个函数来创建文本框。我需要知道是否有办法用新数字替换字符串的结尾。

While x <= tbnumberofitems
        Dim x As Integer = 0 ' looop count '
    Dim y As Integer = 1 ' name count'
    Dim label1name As String = "label"
    Dim textbox1name As String = "textbox"
    While x <= tbnumberofitems
        y = y + 1
        If x = 0 Then y = 1

        Convert.ToString(y)

        Dim label1 As New Label
        label1.Name = label1name & y

        'Code to create label box

        Dim textbox1 As New TextBox
        textbox1.Name = textbox1name & y

        'code to create text box

        x = x + 1


    End While

这是我目前拥有的。我现在需要的是一种方法,使其在下次循环运行时将名称更改为 textbox2 和 label2 在第三个循环标签 3 和文本框 3 等。如果这还不够清楚我想要做什么将其设为numberofitems,设为5,通过程序创建5个标签和5个文本框。

4

1 回答 1

1

基本是这样的。。

For x as Integer = 1 to tbnumberofitems

    'Code to create label
    Dim lbl As New Label
    lbl.Name = "label" & format(x)
    lbl.Location = New Point(10, x*20)
    Me.Controls.Add(lbl)

    'Code to create textbox
    Dim tb As New TextBox
    tb.Name = "TextBox" & format(x)
    tb.Location = New Point(100, x*20)
    Me.Controls.Add(tb)

Next
于 2013-06-11T04:30:58.850 回答