If you want to add any windows form control to container control like Panel,Groupbox etc. or remove control in same manner. Then we can use Controls.Add(obj) and Controls.Remove(obj), on here obj as a parameter any object that derives from the Control class
Example
following example show how to add and remove control to any container control in vb.net. in this example we take Button as control and panel as container control named Panel1
Add Control to container control:
Public NewButton As New Button() Public Sub AddNewControl() Panel1.Controls.Add(NewButton) AddHandler NewButton.Click, AddressOf NewPanelButton_Click End Sub
Remove control from container control:
Public Sub RemoveControl() If Panel1.Controls.Contains(NewButton) Then RemoveHandler NewButton.Click, _ AddressOf NewPanelButton_Click Panel1.Controls.Remove(NewButton) NewButton.Dispose() End If End Sub