Using arrays of controls or custom controls provides a very powerful means of dealing with certain kinds of data manipulation. In this example we will be using this technique to make a simple quiz program.

Simple_Quiz

Step 1 – Creating a Custom Control

Add a new Class to your project. Call it “answerField” and enter TextField as its Super. To answerField add two properties: result as boolean and rightAnswer as string.

ControlArray

 

 

 

Now we will add some code to answerField. Put the following code in the TextChange event of answerField. We will see a bit further on how this code utilizes the two properties (result as boolean, and rightAnswer as string) to keep track of right and wrong answers.

ControlArray 2

 

Step 2 – Creating the Control Array

To Window1 add a Label control for the first question. Also add an TextField for the answer. In the Inspector set the super of the TextField to “answerField” and name it “responseField”. 
Repeat this step to add another Label and TextField. Make sure the new TextField’s super is “answerField”. Again name the TextField “responseField” and hit Enter. When you name the second answerField the same as the first this dialog will appear. Click OK.

Screenshot_2014-05-06__6_38_PM

This creates a control set.

ControlArray 3

Keep adding questions and responseFields in this way until you have 5 questions and responseFields.

Next page