troubleshooting Question

Adding C# Controls to a Windows Form Dynamically.

Avatar of Mr_Fulano
Mr_FulanoFlag for United States of America asked on
C#Microsoft Visual Studio
3 Comments1 Solution173 ViewsLast Modified:
Hi, I'm using Visual Studio 2015 - C#. (I have to admit, I haven't coded in a while, so I'm a bit rusty.)

That said, I have to create a Windows Form Application that will allow the enduser to conduct a survey of several different types of facilities. The application would ask the user questions about each facility and the user would select from a set of predetermined answers (i.e. None, Low, Medium, High, etc) to answer the questions. Each answer would have a predetermined value and all those values would be added up at the end to provide a "total evaluation score." -- That part of the project I think I can accomplish without too much difficulty.

However, my question is this -- since the enduser will have different types of facilities, I wanted to have "one" application and create the controls on the form dynamically depending on what questions and control types are needed for each type of facility. I could use Tab Delimited files to manage the different types.

Therefore, all the questions on the Form will have a Label that makes up the verbiage for the question. And all questions will have a Control of some sort (i.e.. a DropdownBox, or a set of Radio Buttons, or maybe a ComboBox) so, how could I, by way of using Tab Delimited files in conjunction with my Application, add Controls (dynamically) to my Application at Runtime?

More specifically, if I wanted to (dynamical at Runtime) add a Label and a DropdownBox Control to my Form, how would I do that?

Once I figure out the format to do that, I would just have the Application read from a Tab Delimited file - line by line, that would tell the Application which questions to insert into the Form and which Controls go with each specific question.

(Unless you know of a better way to do this, which I would very much like to learn about).

Much like this example below:

                          LABELS                                                                                                           CONTROL                                  CONTROL
   1).  Rate your lighting for your facility.                                                       [DropdownBox - with several choices]         [Score]

   2). Rate your security perimeter (i.e fencing) for your facility.              [DropdownBox - with several choices]          [Score]

   3). Rate your emergency fire suppression for your facility.                   [Radio Buttons - with several choices]          [Score]

In the example above, I would be adding one Label and two Controls to my Form for each question. How to add those Controls dynamically to my Form is my question.

Thank you for your help!

Best Regards,
Fulano
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros