Step 3 of 4: Adding Code to the Application

In the previous steps you set up the application's user interface and added C1NumberBox, Label, and Button controls to your application. In this step you'll add code to your application to finalize it.

Complete the following steps:

1.   Double-click Button1 to switch to Code view and create the Button1_Click event handler.

2.   Add the following imports statements to the top of the page:

      Visual Basic

      C#

3.   Initialize the following global variables just inside class Window1:

      Visual Basic

      C#

These numbers will be used as the correct 'code' in the application. When the user enters the correct combination of numbers at run time the button will appear.

4.   Add code to the Button1_Click event handler so that it appears like the following:

      Visual Basic

      C#

When the button is pressed at run time it will open the ComponentOne Web site.

5.   Next add the following custom NBValidation event to your code:

      Visual Basic

      C#

When the user enters the correct numbers (as indicated in step 3 above) the C1NumericBox controls will be set to read only and will no longer be editable, the text of the label below the controls will change to indicate the correct code has been entered, and a button will appear allowing users to enter the ComponentOne Web site.

6.   Choose View | Designer to return to Design view.

7.   Click C1NumericBox1 to select it, and navigate to the Properties window.

8.   Click the Events (lightning bolt) button on the Properties window to view events.

9.   Double-click the box next to the ValueChanged event. This will switch to Code view and create the C1NumericBox1_ValueChanged event handler.

10.  Enter the code in the C1NumericBox1_ValueChanged event handler to initialize NBValidation. It will look like the following:

      Visual Basic

      C#

11.  Repeat steps 6 to 9 for each additional C1NumericBox control so that NBValidation is initialized in all five.

In this step you completed adding code to your application. In the next step you'll run the application and observe run-time interactions.


Send us comments about this topic.
Copyright © GrapeCity, inc. All rights reserved.