Groups | Blog | Home
all groups > vb.net > january 2006 >

vb.net : Deleting all forms in collection


Yuk Tang
1/14/2006 8:48:20 PM
I have created my own custom forms called baseform, inheriting normal
form properties and such. Baseform is, as can be expected, the basis
for the other forms in my project. I want to close all forms
whenever the x is clicked on any of those forms, so I go to the
closing event and cycle through the forms collection, closing each of
them down like so.

either

Forms(n).Close

or

Systems.Windows.Forms(n).Close

or something similar. But to my surprise, I don't get the count
property as an option to get n number of forms, and manually putting
in a number doesn't offer close as a valid method either. My guess
was that, since baseform inherits from form, so baseform would be
part of the forms collection as a result.

I can work around it by putting in a method that checks and closes
each form by name, but I'd have thought looping through the
collection via index numbers would be a simpler solution.

I have the feeling that I'm missing something obvious here. Can
someone help? Thanks.


--
Jumeli
1/15/2006 12:22:09 AM
Hello,
Cant we use
dim f1 as form
For each f1 in system.windows.forms
if f1.isopen is true f1.close
next

???
Try it out.
Sorry if i dint catch your point.


[quoted text, click to view]

Yuk Tang
1/19/2006 7:55:27 PM
Thanks.


--
AddThis Social Bookmark Button