
34
LESSON 2 Creating Controls
2. Type the bold text in the following code so the event handler looks like this:
// Create the new customer.
private void okButton_Click(object sender, EventArgs e)
{
resultLabel.Text = “New User Created”;
resultLabel.BackColor = Color.LightGreen;
resultLabel.Visible = true;
}
Add code behind the Cancel button to display the result label with a hot pink background
and the text “Operation Canceled.”
1. Double-click the Cancel button to create an event handler for its Click event.
2. Type the bold text in the following code so the event handler looks like this:
// Don’t create the new customer.
private void cancelButton_Click(object sender, EventArgs e)
{
resultLabel.Text = “Operation Canceled”;
resultLabel.BackColor = Color.HotPink;
resultLabel.Visible = true;
}
Now run the code and experiment with the program. Notice what happens when you press the [Enter]
and [Esc] keys while focus is in a
TextBox. See what happens if focus is on one of the buttons.
Please select Lesson 2 on the DVD to view the video that accompanies this lesson.
EXERCISES
1. Build a checkerboard similar to the one
shown in Figure 2-10. (Hints: The squares are
PictureBoxes with different background colors.
Give the form a bluish background. Finally,
use the Format menu or Layout toolbar to align
the controls.)
2. Make a tic-tac-toe (or naughts-and-crosses)
board similar to the ...