|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Deleting controlsI 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 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 > > 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 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 > >
Other interesting topics
How I can find out on which platform I am running (32/64 bits)?
overriding array size How to determine if e-mail was sent OK Add Active Directory Users to a Group on a Workstation regex expressions Windows Service to copy files to a Mapped Drive change date Autorun on USB Flash Drive getting 2005 grid to look like 2003 FolderBrowserDialog questions |
|||||||||||||||||||||||