Example Application: The Progress Clock |
|
Description
This is an example of an application that uses the progress bar to display the current time. It gets the actual time from the computer.
Practical Learning: Creating the Application
Control | Text | Name | Other Properties | |
Label | Time | Anchor: Right | ||
Label | Hours: | |||
ProgressBar | 00 | Anchor: Left, Right | ||
Label | lblHours | |||
Label | Minutes: | |||
ProgressBar | Anchor: Left, Right | |||
Label | 00 | lblMinutes | Anchor: Right | |
Label | Seconds: | |||
ProgressBar | Anchor: Left, Right | |||
Label | 00 | lblSeconds | Anchor: Right | |
Button | Close | btnClose | Anchor: Right | |
Timer | Enabled: True Interval: 20 |
Name | Maximum | Step |
pgrHours | 23 | 1 |
pgrMinutes | 59 | 1 |
pgrSeconds | 59 | 1 |
private void timer1_Tick(object sender, EventArgs e) { // Get the current time DateTime curTime = DateTime.Now; // Retrieve the hour value of the current time int H = curTime.Hour; // Retrieve the minute value of the current time int M = curTime.Minute; // Retrieve the second value of the current time int S = curTime.Second; // Draw the progress boxes based on the values of the time pgrHours.Value = H; pgrMinutes.Value = M; pgrSeconds.Value = S; // Display the values in the corresponding labels lblHours.Text = H.ToString(); lblMinutes.Text = M.ToString(); lblSeconds.Text = S.ToString(); }
private void btnClose_Click(object sender, EventArgs e) { Close(); }
|
||
Home | Copyright © 2010-2022, FunctionX | |
|