Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Cycling through all GUI Objects within a form

Cycling through all GUI Objects within a form

Scheduled Pinned Locked Moved C#
csharptutorialquestion
24 Posts 11 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Anthony Mushrow

    Iterate like people have said, but check the type of the object, and run a separate peice of code to get its items collection, or its child controls etc. Whatever you do, im pretty sure there isn't some simple function you can use, its gonna take quite the chunk of code, and your probably gonna have to write it all yourself.

    K Offline
    K Offline
    karthick n mca
    wrote on last edited by
    #15

    you go to hell.............

    D 1 Reply Last reply
    0
    • M Martin 0

      Don't you think, that this would bring a lot of useless matches (ListBox.Items). I think it would be easier to check out how many control classes don't match "Controls", and do a typecheck ("as") at them!

      All the best, Martin

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #16

      Martin# wrote:

      Don't you think, that this would bring a lot of useless matches (ListBox.Items).

      Since I don't know what the overall purpose is I can't say if that would bring lots of useless matches or not. It might do. It might not.


      Upcoming FREE developer events: * Glasgow: db4o: An Embeddable Database Engine for Object-Oriented Environments, Mock Objects, SQL Server CLR Integration, Reporting Services ... My website

      K 1 Reply Last reply
      0
      • C Colin Angus Mackay

        Then you will have to use reflection to determine if you need to recurse into a Controls collection or an Items collection.


        Upcoming FREE developer events: * Glasgow: db4o: An Embeddable Database Engine for Object-Oriented Environments, Mock Objects, SQL Server CLR Integration, Reporting Services ... My website

        U Offline
        U Offline
        Urs Enzler
        wrote on last edited by
        #17

        I wouldn't use reflection. I'd just test if the current control is of a type with a property Controls or whether it is of for example type ToolStrip: Or the make the code more readable, introduce several overloaded methods that take the different types as a parameter (one overload for control, one for toolstrip, ....) And call them recursively.

        -^-^-^-^-^- no risk no funk ................... please vote ------>

        1 Reply Last reply
        0
        • U Urs Enzler

          Do not forget to check the HasChildren property. Speeds things up.

          -^-^-^-^-^- no risk no funk ................... please vote ------>

          P Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #18

          That may depend on how the enumeration is implemented.

          1 Reply Last reply
          0
          • K karthick n mca

            you go to hell.............

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #19

            Whould you mind explaining yourself?? Undefeated's explanation and suggestion is perfectly valid.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007

            D 1 Reply Last reply
            0
            • C Colin Angus Mackay

              Martin# wrote:

              Don't you think, that this would bring a lot of useless matches (ListBox.Items).

              Since I don't know what the overall purpose is I can't say if that would bring lots of useless matches or not. It might do. It might not.


              Upcoming FREE developer events: * Glasgow: db4o: An Embeddable Database Engine for Object-Oriented Environments, Mock Objects, SQL Server CLR Integration, Reporting Services ... My website

              K Offline
              K Offline
              karoitay
              wrote on last edited by
              #20

              The Overall purpose is to have a dictionary that will map a Gui object to a bitmask to determine its accessibility to each user of the application

              1 Reply Last reply
              0
              • D Dave Kreskowiak

                Whould you mind explaining yourself?? Undefeated's explanation and suggestion is perfectly valid.

                A guide to posting questions on CodeProject[^]
                Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                     2006, 2007

                D Offline
                D Offline
                Dan Neely
                wrote on last edited by
                #21

                but it wasn't something that could be copy/pasted as is to do the OPs homework/job for him. Consequently it was worthless. :mad:

                -- If you view money as inherently evil, I view it as my duty to assist in making you more virtuous.

                1 Reply Last reply
                0
                • K karoitay

                  I Have just recently heard about reflection and I'm quite not familiar with the subject. So... can you please hand me a little piece of code to show how can this be done so I will not have to read all about reflection. ( I'm a litle busy the next days any I need this job to be done as quickly as possible ). Thanks.

                  J Offline
                  J Offline
                  J4amieC
                  wrote on last edited by
                  #22

                  karoitay wrote:

                  I'm a litle busy the next days any I need this job to be done as quickly as possible

                  Gee, why didn't you say so. I'll get right on it. :rolleyes:

                  --- How to get answers to your questions[^]

                  1 Reply Last reply
                  0
                  • K karoitay

                    I Have just recently heard about reflection and I'm quite not familiar with the subject. So... can you please hand me a little piece of code to show how can this be done so I will not have to read all about reflection. ( I'm a litle busy the next days any I need this job to be done as quickly as possible ). Thanks.

                    C Offline
                    C Offline
                    Colin Angus Mackay
                    wrote on last edited by
                    #23

                    You can ask every object for its type with .GetType(). You get back a Type object. It has methods on it such as GetMethod, GetProperty and so on. You can get information from the objects those methods return MethodInfo or PropertyInfo and so on. If you find the one you want you can then Invoke it. Most of this should make enough sense through intellisense. You may have to look up some stuff in the documentation though. It really is worth reading up on so you have a better understanding of the environment in which you are working.


                    Upcoming FREE developer events: * Glasgow: db4o: An Embeddable Database Engine for Object-Oriented Environments, Mock Objects, SQL Server CLR Integration, Reporting Services ... My website

                    K 1 Reply Last reply
                    0
                    • C Colin Angus Mackay

                      You can ask every object for its type with .GetType(). You get back a Type object. It has methods on it such as GetMethod, GetProperty and so on. You can get information from the objects those methods return MethodInfo or PropertyInfo and so on. If you find the one you want you can then Invoke it. Most of this should make enough sense through intellisense. You may have to look up some stuff in the documentation though. It really is worth reading up on so you have a better understanding of the environment in which you are working.


                      Upcoming FREE developer events: * Glasgow: db4o: An Embeddable Database Engine for Object-Oriented Environments, Mock Objects, SQL Server CLR Integration, Reporting Services ... My website

                      K Offline
                      K Offline
                      karoitay
                      wrote on last edited by
                      #24

                      Thanks, I'll check it out.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups