1

i want to retrieve all of the controls in specific windows form. im thinking to get all of them in the file designer.cs(ex:form1.designer.cs). i know some here maybe thinking just foreach loop controls in form1.controls but not like that.Currently im opening the designer.cs file in richtextbox but somehow did not meet my requirement i just want to retrieve the controls on that file

lankean
  • 11
  • 5

1 Answers1

1

I Assume by designer.cs you mean all the controls in you Form(WindowsForm)

You need to recursively query for all the controls in the Form Here are two links which will help you get what you are asking for.

How can I query all Childcontrols of a Winform recursively?

How to get ALL child controls of a Windows Forms form of a specific type (Button/Textbox)?

Community
  • 1
  • 1
Guru Kara
  • 6,272
  • 3
  • 39
  • 50
  • i think you misunderstood it i mean i wanna get all the controls in form1 for example and when i get all of the controls im gonna use that in different project so if you think i cant get them if i run form1 and used that code youve link for me inside form1.so im thinking maybe i can get them on the file of form1.designer.cs and when i get the controls i can use them on another project – lankean Mar 13 '14 at 05:51
  • for clarification;example i have two projects(project1 and project 2) theyre open on different visual studio.project 2 will retrieve all the controls of form1 under project1.thats why i said while ago maybe i can retrive them in form1.designer.cs and when i retrieve the controls i can use them in project2. – lankean Mar 13 '14 at 05:56
  • pls help me if you had any idea how i can overcome that. – lankean Mar 13 '14 at 05:57
  • Cant you add reference to other Project2 in Project1 and then create a instance of Form1 and then use the functions given above ? – Guru Kara Mar 13 '14 at 07:50
  • no i cant do that and must i must not do that, cause Project 1 is only an example, the program im creating is dynamic it doesnt always rely on project 1.think of it as a tool in programming. – lankean Mar 13 '14 at 07:58
  • Ahh i see, In that case if at all possible try to switch to WPF. WPF uses XAML, you can lot easily parse an XAML-XML for relationship than a flat file (.cs) file. Other approach would be to load the assembly using reflection and then work through it. Parsing a .cs file as a textfile is definitely not recommended. – Guru Kara Mar 13 '14 at 08:04
  • Also you better modify the question to get more help. – Guru Kara Mar 13 '14 at 08:06
  • what you mean by load assembly using reflection?i cant switch to xaml cause this is for winforms only. – lankean Mar 14 '14 at 05:21