Home All Groups Group Topic Archive Search About
Author
23 Dec 2006 10:57 AM
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

Author
23 Dec 2006 8:45 PM
Martin
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

Show quoteHide quote
"WH" <willy.hae***@skynet.be> wrote in message
news:458d0ba5$0$30044$ba620e4c@news.skynet.be...
>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
>
>
Are all your drivers up to date? click for free checkup

Author
27 Dec 2006 1:09 PM
davidhosking
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
Author
27 Dec 2006 3:20 PM
Cor Ligthert [MVP]
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

Show quoteHide quote
"WH" <willy.hae***@skynet.be> schreef in bericht
news:458d0ba5$0$30044$ba620e4c@news.skynet.be...
>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
>
>

Bookmark and Share