112
LESSON 9 Creating and displaying new Forms
theGettingAroundForm.Show();
}
// Display the lodging form.
private void lodgingButton_Click(object sender, EventArgs e)
{
theLodgingForm.Show();
}
// Display the fun stuff form.
private void funnStuffButton_Click(object sender, EventArgs e)
{
theFunStuffForm.Show();
}
Please select Lesson 9 on the DVD to view the video that accompanies this lesson.
EXERCISES
1. Make a program that displays a Button that says “New Form.” When the user clicks the
Button, display a new non-modal instance of the same kind of form. (What happens when
you click the new form’s button? What happens if you close the new form? What happens if
you make several forms and close the original one?)
2. Copy the program you made for Exercise 1 and add a TextBox named valueTextBox to the
form. Before you display the new form, copy the main form’s
TextBox value into the new
form’s
TextBox. (Hint: You don’t need to set the TextBox’s Modifiers property to Public
because the new form is the same kind as the old one. You need to do this only if a form of
one type wants to peek at the controls on a form of a different type.)
3. Make a program that displays a TextBox and a “New Form” Button. When the user clicks
the
Button, display a new form of type MessageForm modally.
The
MessageForm holds two Labels. The first Label says “You entered.” The second Label
is blank. When it displays the
MessageForm, the main program should copy whatever is
in its
TextBox into the MessageForm’s second label. (Hint: Now you need to set the label’s
Modifiers property to Public.)
4. Build the PickAPicture program shown in Figure 9-6. When the user clicks one of the thumb-
nail images on the main form, the program displays a
PictureForm showing the image at full
scale. Use whatever images you like. (Hints: Display the thumbnail images in
PictureBoxes
with
ScaleMode set to Zoom. Set the PictureForm’s BackgroundImage property equal to the
PictureBox’s Image value.)
5. Extra Credit: As I’ve mentioned before, redundant code is usually a sign that the pro-
gram’s structure can be improved. The PickAPicture program from Exercise 4 uses four
practically identical event handlers. The only difference is the image that they assign to the
PictureForm’s background.
596906c09.indd 112 4/7/10 12:32:20 PM