从中间覆盖一个字符串

时间:2013-06-11 04:25:12

标签: vb.net str-replace

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

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

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

1 个答案:

答案 0 :(得分: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