-1

i have a problem. I have a button who is creating an other button, but i want that the new button will be in a groupbox, but it's not working, the button is replacing all of the groupbox.

Private Sub button1_Click(sender As Object, e As EventArgs) Handles button1.Click
    Dim button As New Button
    button.Location = New Drawing.Point(10, 500)
    button.Size = New System.Drawing.Size(171, 23)
    button.Text = TextBox1.Text
    button.Controls.Add(GroupBox1)
    Me.Controls.Add(button)

End Sub    

Thanks

Jonathan Carroll
  • 880
  • 1
  • 5
  • 20
Touyoo
  • 1
  • 1
  • 2

1 Answers1

2
button.Controls.Add(GroupBox1)

Here you are adding the GroupBox to the Button, not the other way around.

GroupBox1.Controls.Add(button)

Is what you want.