Results 1 to 8 of 8

Thread: Iterating forms? [given up. unsolved]

  1. #1

    Thread Starter
    Fanatic Member BrianHawley's Avatar
    Join Date
    Aug 2001
    Location
    Saudi Arabia
    Posts
    796

    Iterating forms? [given up. unsolved]

    Anybody know how to iterate forms?

    In VB6 it would be something like:

    VB Code:
    1. 'Do each form
    2.   For i = 0 To Forms.Count - 1
    3.         Forms(i).Caption = "Got it!"
    4.   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)

  2. #2

  3. #3

    Thread Starter
    Fanatic Member BrianHawley's Avatar
    Join Date
    Aug 2001
    Location
    Saudi Arabia
    Posts
    796
    Can you be a bit more specific?
    Brian
    (Fighting with the RightToLeft bugs in VS 2005)

  4. #4
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,539
    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)

  5. #5
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    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

  6. #6
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    .
    Last edited by DevGrp; Apr 24th, 2002 at 01:23 PM.

  7. #7

    Thread Starter
    Fanatic Member BrianHawley's Avatar
    Join Date
    Aug 2001
    Location
    Saudi Arabia
    Posts
    796
    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)

  8. #8
    Hyperactive Member Scott Penner's Avatar
    Join Date
    Dec 2000
    Location
    Mountain View
    Posts
    327
    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
  •  



Click Here to Expand Forum to Full Width