Deleting controls

  • Thread starter Thread starter WH
  • Start date Start date
W

WH

I put a few controls on a form at runtime like
Dim bt as Button
For n = to to 5
bt = new Button
...
Me.Controls.add(bt)
Next

How can I again delete them at runtime? I tried
For each bt in Me.controls
bt.dispose()
Next

But only a few controls disappear, some stay on the form.
bt = Nothing() does'nt do the job either
Is there a way to completely discard then from the form and from memory?
Thanks
WH
 
You could add them to a collection as they are created and then refer to the
collection to remove them from the form later. I'm sure there are other ways
as well but this would work.

HTH

Martin
 
Hi WH,

You must remember to remove them from the form before disposing them.
So just before you dispose them, use me.controls.remove(bt).

Regards
 
Willy,

You add the buttons to the controls with Add, what command do you think
there is to Remove them from the Controls?

Keep in mind that if you remove buttons from a parent control that you do it
bottom up because the index is everytime regenerated.

It depends on were you created the buttons when they will be garbaged, but
normally you can forget to take actions in that because the Garbage
Collector does that.

Cor
 
Back
Top