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. Get the list of Controls in the windows application

Get the list of Controls in the windows application

Scheduled Pinned Locked Moved C#
helpcsharpxml
7 Posts 4 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.
  • H Offline
    H Offline
    Huzefa_Incredible
    wrote on last edited by
    #1

    Hi guys, I am having a problem in my application..the prob is that i wanna get the list of controls on the other form...so what i have done is that 1> I have instantiate the form of which i wanna get the Control list 2> Recurse through a foreach loop and get each control and put the details in a XML file.. Now the main prob that is arising is that the controls are comin i the form in any order(ie textbox,button,textbox etc) and i want to recurse in the order of top to bottom and left to right(ie first label then textbox then again a label and then textbox and so on). the i have implemented is Code: ( text )Form2 frm = new Form2(); foreach (System.Windows.Forms.Control ctr in frm.Controls) { .....//some codes here }
    if anyone can help plz reply and for further clarification do reply....

    .Net Developer

    I 1 Reply Last reply
    0
    • H Huzefa_Incredible

      Hi guys, I am having a problem in my application..the prob is that i wanna get the list of controls on the other form...so what i have done is that 1> I have instantiate the form of which i wanna get the Control list 2> Recurse through a foreach loop and get each control and put the details in a XML file.. Now the main prob that is arising is that the controls are comin i the form in any order(ie textbox,button,textbox etc) and i want to recurse in the order of top to bottom and left to right(ie first label then textbox then again a label and then textbox and so on). the i have implemented is Code: ( text )Form2 frm = new Form2(); foreach (System.Windows.Forms.Control ctr in frm.Controls) { .....//some codes here }
      if anyone can help plz reply and for further clarification do reply....

      .Net Developer

      I Offline
      I Offline
      il_masacratore
      wrote on last edited by
      #2

      You're using the easy way. If you want to recurse and order it from location you have to check every control position and begin to order it. The order of controls maintains the jerarchy (containers jerarchy) but real order is the order in whic you have inserted controls(see designer file).

      Visit my blog at http://dotnetforeveryone.blogspot.com

      P H 2 Replies Last reply
      0
      • I il_masacratore

        You're using the easy way. If you want to recurse and order it from location you have to check every control position and begin to order it. The order of controls maintains the jerarchy (containers jerarchy) but real order is the order in whic you have inserted controls(see designer file).

        Visit my blog at http://dotnetforeveryone.blogspot.com

        P Offline
        P Offline
        pmarfleet
        wrote on last edited by
        #3

        il_masacratore wrote:

        The order of controls maintains the jerarchy (containers jerarchy)

        You mean hierarchy?

        Paul Marfleet

        1 Reply Last reply
        0
        • I il_masacratore

          You're using the easy way. If you want to recurse and order it from location you have to check every control position and begin to order it. The order of controls maintains the jerarchy (containers jerarchy) but real order is the order in whic you have inserted controls(see designer file).

          Visit my blog at http://dotnetforeveryone.blogspot.com

          H Offline
          H Offline
          Huzefa_Incredible
          wrote on last edited by
          #4

          hey the blog for which you have created a link is in some other language then english...plz tell how to convert it in english otherwise please explain in detail as to how get the location of the controls and then add them in the xml file...Please help!!!!!!

          .Net Developer

          C 1 Reply Last reply
          0
          • H Huzefa_Incredible

            hey the blog for which you have created a link is in some other language then english...plz tell how to convert it in english otherwise please explain in detail as to how get the location of the controls and then add them in the xml file...Please help!!!!!!

            .Net Developer

            C Offline
            C Offline
            Christian Wikander
            wrote on last edited by
            #5

            You cannot get them in any particular order from the controls collection. You will need to loop through the controls collection several times, finding out which control to fetch for every loop. It should also be possible to add all the controls to a SortedList and write a custom comparer that can determine if one control should be sorted before another depending on Left and Top properties if that is what you want.

            H 1 Reply Last reply
            0
            • C Christian Wikander

              You cannot get them in any particular order from the controls collection. You will need to loop through the controls collection several times, finding out which control to fetch for every loop. It should also be possible to add all the controls to a SortedList and write a custom comparer that can determine if one control should be sorted before another depending on Left and Top properties if that is what you want.

              H Offline
              H Offline
              Huzefa_Incredible
              wrote on last edited by
              #6

              i dont think thats possible...as for me i am creatin an application where i want to convert the whole form presented to me into an XML file and this is dynamically so i dnt knw which controls are there and in which order i just want to fetch those controls on the form in the order in which we usually put the controls ie top to bottom and left to right.. the form may have 10controls also and 50 controls also...

              .Net Developer

              C 1 Reply Last reply
              0
              • H Huzefa_Incredible

                i dont think thats possible...as for me i am creatin an application where i want to convert the whole form presented to me into an XML file and this is dynamically so i dnt knw which controls are there and in which order i just want to fetch those controls on the form in the order in which we usually put the controls ie top to bottom and left to right.. the form may have 10controls also and 50 controls also...

                .Net Developer

                C Offline
                C Offline
                Christian Wikander
                wrote on last edited by
                #7

                I don't see a contradiction there. You just need to define rules to determine how to sort the controls. You will need the rules anyway you turn, because there is no such sorting built in.

                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