-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFig-8.07 - TimeTest3.cs
More file actions
215 lines (173 loc) · 5.24 KB
/
Copy pathFig-8.07 - TimeTest3.cs
File metadata and controls
215 lines (173 loc) · 5.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
// Fig. 8.7: TimeTest3.cs
// Demonstrando as propriedades Hour, Minute e Second de Time3.
using System;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
// Cole a classe Time3 (Fig-8.06 - Time3.cs) aqui.
partial class TimeTest3 : Form
{
private Time3 time;
private Label hourLabel;
private TextBox hourTextBox;
private Button hourButton;
private Label minuteLabel;
private TextBox minuteTextBox;
private Button minuteButton;
private Label secondLabel;
private TextBox secondTextBox;
private Button secondButton;
private Button addButton;
private Label displayLabel1;
private Label displayLabel2;
private void InitializeComponent()
{
this.time = new Time3();
this.hourLabel = new Label();
this.hourTextBox = new TextBox();
this.hourButton = new();
this.minuteLabel = new Label();
this.minuteTextBox = new TextBox();
this.minuteButton = new Button();
this.secondLabel = new Label();
this.secondTextBox = new TextBox();
this.secondButton = new Button();
this.addButton = new Button();
this.displayLabel1 = new Label();
this.displayLabel2 = new Label();
// hourLabel.
this.hourLabel.Name = "hourLabel";
this.hourLabel.Text = "Hour:";
this.hourLabel.AutoSize = true;
this.hourLabel.Location = new Point(10, 10);
// hourTextBox.
this.hourTextBox.Name = "hourTextBox";
this.hourTextBox.Text = "18";
this.hourTextBox.Size = new Size(30, 20);
this.hourTextBox.Location = new Point(60, 5);
// hourButton.
this.hourButton.Name = "hourButton";
this.hourButton.Text = "Set Hour";
this.hourButton.Location = new Point(100, 5);
this.hourButton.Click += new EventHandler(hourButton_Click);
// minuteLabel.
this.minuteLabel.Name = "minuteLabel";
this.minuteLabel.Text = "Minute:";
this.minuteLabel.AutoSize = true;
this.minuteLabel.Location = new Point(10, 40);
// minuteTextBox.
this.minuteTextBox.Name = "minuteTextBox";
this.minuteTextBox.Text = "01";
this.minuteTextBox.Size = new Size(30, 20);
this.minuteTextBox.Location = new Point(60, 35);
// minuteButton.
this.minuteButton.Name = "minuteButton";
this.minuteButton.Text = "Set Minute";
this.minuteButton.Location = new Point(100, 35);
this.minuteButton.Click += new EventHandler(minuteButton_Click);
// secondLabel.
this.secondLabel.Name = "secondLabel";
this.secondLabel.Text = "Second:";
this.secondLabel.AutoSize = true;
this.secondLabel.Location = new Point(10, 70);
// secondTextBox.
this.secondTextBox.Name = "secondTextBox";
this.secondTextBox.Text = "20";
this.secondTextBox.Size = new Size(30, 20);
this.secondTextBox.Location = new Point(60, 65);
// secondButton.
this.secondButton.Name = "secondButton";
this.secondButton.Text = "Set Second";
this.secondButton.Location = new Point(100, 65);
this.secondButton.Click += new EventHandler(secondButton_Click);
// addButton.
this.addButton.Name = "addButton";
this.addButton.Text = "Add 1 to Second";
this.addButton.AutoSize = true;
this.addButton.Location = new Point(100, 95);
this.addButton.Click += new EventHandler(addButton_Click);
// displayLabel1.
this.displayLabel1.Name = "displayLabel1";
this.displayLabel1.Text = "";
this.displayLabel1.AutoSize = true;
this.displayLabel1.Location = new Point(190, 10);
// displayLabel2.
this.displayLabel2.Name = "displayLabel2";
this.displayLabel2.Text = "";
this.displayLabel2.AutoSize = true;
this.displayLabel2.Location = new Point(190, 30);
// TimeTest3.
this.Controls.AddRange(new Control[]{
this.hourLabel, this.hourTextBox, this.hourButton,
this.minuteLabel, this.minuteTextBox, this.minuteButton,
this.secondLabel, this.secondTextBox, this.secondButton,
this.addButton, this.displayLabel1, this.displayLabel2,
});
this.Name = "TimeTest3";
this.Text = "TimeTest3";
this.AutoSize = true;
this.ResumeLayout(false);
}
public void UpdateDisplay()
{
displayLabel1.Text = "Hour: " + time.Hour +
"; Minute: " + time.Minute +
"; Second: " + time.Second;
displayLabel2.Text = "Standard time: " +
time.ToStandardString() + "\nUniversal time: " +
time.ToUniversalString();
}
private void hourButton_Click(object? sender, EventArgs e)
{
time.Hour = Int32.Parse(hourTextBox.Text);
hourTextBox.Text = "";
UpdateDisplay();
}
private void minuteButton_Click(object? sender, EventArgs e)
{
time.Minute = Int32.Parse(minuteTextBox.Text);
minuteTextBox.Text = "";
UpdateDisplay();
}
private void secondButton_Click(object? sender, EventArgs e)
{
time.Second = Int32.Parse(secondTextBox.Text);
secondTextBox.Text = "";
UpdateDisplay();
}
private void addButton_Click(object? sender, EventArgs e)
{
time.Second = (time.Second + 1) % 60;
if (time.Second == 0)
{
time.Minute = (time.Minute + 1) % 60;
if (time.Minute == 0)
time.Hour = (time.Hour + 1) % 24;
}
UpdateDisplay();
}
}
partial class TimeTest3
{
private Container? components = null;
public TimeTest3()
{
InitializeComponent();
UpdateDisplay();
}
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{ components.Dispose(); }
base.Dispose(disposing);
}
}
static class Program
{
[STAThread]
static void Main()
{
ApplicationConfiguration.Initialize();
Application.Run(new TimeTest3());
}
}