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