VB.net代码有些困难

时间:2012-06-07 07:27:18

标签: .net vb.net

我是WinForms VB .NET编程的初学者。我需要在运行时创建文本框。

我在搜索引擎中找到了如何实现这个的例子:

Private Sub Command1_Click()
    Dim TextControl As TextBox
    ControlID = ControlID + 1
    Load Text1(ControlID)
    Set TextControl = Text1(ControlID)
    With TextControl
        .Left = (Text1(ControlID - 1).Left + Text1(ControlID - 1).Width) + 10
        .Top = 20
        .Width = 100
        .Height = 20
        .Visible = True
    End With
End Sub

但是我对示例代码有些困难。

有人会解释以下VB NET代码行吗?

    Load Text1(ControlID)
    Set TextControl = Text1(ControlID)
    With TextControl
    End With

3 个答案:

答案 0 :(得分:3)

您可以查看以下完全符合您要求的示例:

Private Sub btnCreateTextbox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateTextbox.Click
    Dim textbox1 As New TextBox
    textbox1.Name = "Textbox1"
    textbox1.Size = New Size(170, 20)
    textbox1.Location = New Point(167, 32)
    GroupBox1.Controls.Add(textbox1)
End Sub

寻找参考和良好解释:http://www.authorcode.com/create-dynamic-textbox-and-label-in-vb-net/

答案 1 :(得分:1)

这是VB代码。

“加载Text1(ControlID)” 它意味着将Text1(controlID)加载到内存中,Text1(controlID)是一个文本框控件。

答案 2 :(得分:1)

在设计文件中生成的相同代码的设计时间在所需位置添加文本框。复制代码并粘贴到Command1_Click()。

相关问题