在VB.net中创建一个按钮,在按钮下方创建5个文本框(彼此相邻)

时间:2013-10-20 04:54:26

标签: vb.net button gridview

我尝试了下面粘贴的代码,但它似乎不适用于vb.net。但是,这只会创建一个文本框,而不是我想要的文本框。我的目标是在相应的标签下创建5个文本框。然后会有一个按钮,它将从文本框中获取所有文本输入并在网格视图中显示它。

   Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click

    Dim num As Integer
    Dim pos As Integer
    Dim intcount As Integer



    For intcount = 0 To num() - 1

    Next
    Txtdynamic = New TextBox
    Txtdynamic.Width = 20
    Txtdynamic.Visible = True
    Txtdynamic.MaxLength = 1
    Txtdynamic.Location = New Point(pos() + 5, 0)
    pos = pos() + 30

End Sub

This is how my buttons with the labels look like:

<p>
            <asp:Button ID="Button4" runat="server" Text="Add Member" />
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:Button ID="Button5" runat="server" Text="Add Joint" />
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:Button ID="Button6" runat="server" Text="Edit Member" />
 &nbsp;&nbsp;&nbsp;
            <asp:Button ID="Button7" runat="server" Text="Edit Joint" />
 &nbsp;&nbsp;&nbsp;
            <asp:Button ID="Button8" runat="server" Text="See Joint Coordinate" />
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:Button ID="Button9" runat="server" Text="See Member Coordinate" />
        </p>
        Joint #&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Coordinates&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; B.C&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Joint Loads&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; Settlements&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Joint Rotation<p>
    &nbsp;&nbsp;&nbsp;

1 个答案:

答案 0 :(得分:0)

如果将所有指令放在循环块之外,你应该如何进行循环?

尝试这种方式:

For i as short = 0 To 4 ' 0 1 2 3 4 = 5

    Txtdynamic = New TextBox
    Txtdynamic.Width = 20
    Txtdynamic.Visible = True
    Txtdynamic.MaxLength = 1
    Txtdynamic.Location = New Point(pos + 5, 0)
    pos += 30

Next

无论如何,你可以在这里看到一个随机的例子,在执行时添加控件:

Dim ControlArray(5) As CheckBox ' (5): The number of controls to create.

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    For num As Int64 = 0 To ControlArray.LongLength - 1

        ControlArray(num) = New CheckBox ' Create the control instance
        ControlArray(num).Name = "CheckBox " & num      ' Name example  : CheckBox 0
        ControlArray(num).Text = ControlArray(num).Name ' String example: CheckBox 0
        ControlArray(num).Top = num * 20 ' Adjust the location of each control.
        Me.Controls.Add(ControlArray(num)) ' Add the control to a control collection.
        AddHandler ControlArray(num).CheckedChanged, AddressOf CheckBoxSub ' Add a event handler to a procedure.

    Next

End Sub

Public Sub CheckBoxSub(ByVal sender As Object, ByVal e As EventArgs) ' Procedure which is handling the controls.

    If sender.Checked = True Then MsgBox(sender.name & " is checked") Else MsgBox(sender.name & " is unchecked")

    ControlArray(2).Text = "Check Me!" ' CheckBox 2.Text = "Check Me!"

End Sub