Click to See Complete Forum and Search --> : Trying to remove controls at runtime


Deebo
February 15th, 2000, 03:10 PM
I have created 100 picture boxes on anouther picture box. I did this using "Public WithEvents extStars As PictureBox" and adding them with this libne of code
"Set extStars = frmGMap.Controls.Add("vb.picturebox", stStarID, Picture2)". Now I am trying to remove them so I can lay down a different set of pictures. I tried using the only example given in MSDN which was "frmGMap.Controls.Remove (stStarID)". If any one could please give me a hand I would be grateful.

Thanks,
Deebo

Johnny101
February 15th, 2000, 04:27 PM
If the controls are in a control array, why couldn't you just use the unload method?
paste this code in a form and then run it, look at the text boxes, then double click the form and watch them disappear.

'txtMain(0).text was created by hand at design time
option Explicit

private Sub Form_DblClick()
Unload txtMain(2)
Unload txtMain(1)
End Sub

private Sub Form_Load()
Dim ctl as TextBox
Load txtMain(1)
txtMain(1).Left = 0
txtMain(1).Top = 0
Load txtMain(2)
txtMain(2).Left = 200
txtMain(2).Top = 200
Load txtMain(3)
txtMain(3).Left = 400
txtMain(3).Top = 400

for Each ctl In me.Controls
ctl.Visible = true
next
End Sub




Hope this helps,
john


John Pirkey
MCSD
www.ShallowWaterSystems.com

Deebo
February 17th, 2000, 08:40 AM
What I've done is put those controls inside a picture box that is inside anouther picture box. So usnig your method how would I specify that I want the controls to go inside of a picture box. The way I did it I specified where the control should go. It looks like your way only places the control on the form itself and not on anything else. Now I have never used your method before so I might be over looking how to do it. So any help there would be gratefully accepted.

Thank You Again,
Deebo

Deebo
February 17th, 2000, 09:00 AM
I played with it some more and I have got your code to work with what I need. Thank You so much for your help.


Deebo