|
-
Apr 23rd, 2002, 07:03 AM
#1
Thread Starter
Fanatic Member
Iterating forms? [given up. unsolved]
Anybody know how to iterate forms?
In VB6 it would be something like:
VB Code:
'Do each form
For i = 0 To Forms.Count - 1
Forms(i).Caption = "Got it!"
Next i
In C#?
Code:
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.
Last edited by BrianHawley; Apr 25th, 2002 at 05:49 AM.
Brian
(Fighting with the RightToLeft bugs in VS 2005)
-
Apr 24th, 2002, 05:03 AM
#2
Frenzied Member
since forms are "classes"
looks like you have to look into "Reflection"
-
Apr 24th, 2002, 06:13 AM
#3
Thread Starter
Fanatic Member
Can you be a bit more specific?
Brian
(Fighting with the RightToLeft bugs in VS 2005)
-
Apr 24th, 2002, 10:57 AM
#4
Frenzied Member
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)
-
Apr 24th, 2002, 01:19 PM
#5
Frenzied Member
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
-
Apr 24th, 2002, 01:19 PM
#6
Frenzied Member
Last edited by DevGrp; Apr 24th, 2002 at 01:23 PM.
-
Apr 25th, 2002, 05:33 AM
#7
Thread Starter
Fanatic Member
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.
Brian
(Fighting with the RightToLeft bugs in VS 2005)
-
Apr 29th, 2002, 12:06 PM
#8
Hyperactive Member
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.
-scott
he he he
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|