How to add textboxes, labels and buttons dynamically at runtime in VB?

后端 未结 5 1513
滥情空心
滥情空心 2021-01-06 19:25

How to create a form with a button add_subjects which adds one textbox and a corresponding label on each click,3 buttons - Add, Edit and Dele

5条回答
  •  [愿得一人]
    2021-01-06 19:31

    Create dynamic Textbox]

    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
    

    Create Dynamic Label]

    Private Sub lblCreateLabel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblCreateLabel.Click
        Dim label1 As New Label
        label1.Name = "label1"
        label1.Text = "Enter Name"
        label1.AutoSize = True
        label1.Location = New Point(80, 33)
        GroupBox1.Controls.Add(label1)
    End Sub
    

    Refer Here

    Source

提交回复
热议问题