Click to See Complete Forum and Search --> : Iterating forms? [given up. unsolved]
BrianHawley
Apr 23rd, 2002, 07:03 AM
Anybody know how to iterate forms?
In VB6 it would be something like:
'Do each form
For i = 0 To Forms.Count - 1
Forms(i).Caption = "Got it!"
Next i
In C#?
foreach (Form f in ?????????????)
{
f.Text="Got it!"
}
I'm guessing it must be something easy and trivial, but I can't seem to get anyting to work.
kovan
Apr 24th, 2002, 05:03 AM
since forms are "classes"
looks like you have to look into "Reflection"
BrianHawley
Apr 24th, 2002, 06:13 AM
Can you be a bit more specific?
kovan
Apr 24th, 2002, 10:57 AM
what i mean is that since forms are ojbects, and so is everything else, to be able to determine information on objects as far as i know you have to use the reflection namespace
search for Reflection in .NET
(thats the only way i know how to do it, if anyone knows a better way please say so)
DevGrp
Apr 24th, 2002, 01:19 PM
This is not guaranted, but you can try this. Declare a collection, Then after each form is created, insert that form in the collection, then later you can iterate through the collection.
Hope that helps
DevGrp
Apr 24th, 2002, 01:19 PM
.
BrianHawley
Apr 25th, 2002, 05:33 AM
Originally posted by DevGrp
This is not guaranted, but you can try this. Declare a collection, Then after each form is created, insert that form in the collection, then later you can iterate through the collection.
Hope that helps
Yes, I did think of that - but it seems incredible that there is no easier way to get refrences to all forms loaded by an application.
Guess I'll have to settle for iterating the MDI Children, which is quite easy.
Scott Penner
Apr 29th, 2002, 12:06 PM
This might be a hack, but...
You could use global ArrayList object to keep track of forms as they are opened. In the closed(ing?) event of each form, you could removed the form object from the ArrayList. Then, whenever you need to step through the open form collection, it's available.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.