Exercises
185
Step-by-Step
Start a new project and add a
Label to its form.
1. Create the new project and its Label.
2. Set the Label’s AutoSize property to False and set its font size to 12. Then position
and anchor it on the form.
3. Set the Label’s TextAlign property to MiddleCenter.
Give the form a
Load event handler that sets the Label’s text as shown in Figure 14-1.
1. Use code similar to the following:
// Display the current date and time.
private void Form1_Load(object sender, EventArgs e)
{
greetingLabel.Text = DateTime.Now.ToString(
“‘It is’ h:mmtt ‘on’ ddd, MMM dd yyyy”);
}
Please select Lesson 14 on the DVD to view the video that accompanies this lesson.
EXERCISES
1. Lesson 13’s Try It reads and displays currency values, but it displays quantities without
thousands separators. If you ordered 1,200 pencils, the program would display 1200.
Copy that program (or download the Lesson 13 Try It from the book’s web site) and modify
it so quantities are displayed with thousands separators.
2. Make a program that displays the time every second. Hint: Use a Timer control with
Enabled set to True, and Interval set to 1000. Update a Label’s Text property in the
Timer’s Tick event.
3. Copy the program that you built for Exercise 1 and modify it so the main form displays items
in a
ListBox instead of a ListView. Make the program use string.Format to add items to
the
ListBox in a format similar to the following:
1,200 Gummy slugs at $0.02 each = $24.00
4. Make a program that replaces all occurrences of the letter e in a string entered by the user
with the character -.
You can download the solutions to these exercises from the book’s web page at
www.wrox.com or www.CSharpHelper.com/24hour.html. They can be found in
the Lesson14 folder.
596906c14.indd 185 4/7/10 12:32:56 PM
Click here to Play
596906c14.indd 186 4/7/10 12:32:56 PM
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.225.92.184