remove control from tab page

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can anyone tell me how to programmatically remove a control from a tab page
from VB .Net? The control was added using:

Me.TabPage1.Controls.Add(pb)

but I don't know what its index number is to remove it using:

Me.TabPage1.Controls.RemoveAt(index)

and Me.TabPage1.Controls.Remove(pb) doesn't work.

Thanks for any help provided,
Stephanie
 
Hi Stephanie

If you declare the object pb as a form level variable then

Me.TabPage1.Controls.Remove(pb) works

otherwise if pb is a local variable, give it a name when you create it
e.g pb.name = "pb"

then in a loop find it

For Each ctrl As Control In Me.TabPage1.Controls

If ctrl.Name = "pb" Then

Me.TabPage1.Controls.Remove(ctrl)

Exit For

End If

Next



Regards

Steve
 
Back
Top