0

我尝试了下面粘贴的代码,但它似乎在 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;
4

1 回答 1

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
于 2013-10-20T07:43:59.863 回答