-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
279 lines (262 loc) · 8.51 KB
/
Form1.cs
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
namespace WinFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.KeyPreview = true;
}
private void Form1_Load(object sender, EventArgs e)
{
q2.Visible = false;
q3.Visible = false;
txtAns2.Visible = false;
txtAns3.Visible = false;
sub2.Visible = false;
sub3.Visible = false;
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Return)
{
if (sub1.Visible == true)
{
sub1.PerformClick();
}
else if (sub2.Visible == true)
{
sub2.PerformClick();
}
else if (sub3.Visible == true)
{
sub3.PerformClick();
}
e.Handled = true;
}
}
private void sub1_Click(object sender, EventArgs e)
{
Start();
}
private void sub2_Click(object sender, EventArgs e)
{
Q2();
}
private void sub3_Click(object sender, EventArgs e)
{
var txt1 = txtAns2.Text;
if (txt1 == "cf")
{
ConvCtoF();
}
else if (txt1 == "ck")
{
ConvCtoK();
}
else if (txt1 == "fc")
{
ConvFtoC();
}
else if (txt1 == "fk")
{
ConvFtoK();
}
else if (txt1 == "kc")
{
ConvKtoC();
}
else if (txt1 == "kf")
{
ConvKtoF();
}
}
private void Start()
{
string get1 = txtAns1.Text;
string ans1 = get1.ToLower();
List<string> c = new List<string> { "celsius", "c" };
List<string> f = new List<string> { "fahrenheit", "f" };
List<string> k = new List<string> { "kelvin", "k" };
if (c.Contains(ans1))
{
para.Text = "";
txtAns2.Visible = true;
sub2.Visible = true;
q2.Visible = true;
q2.Text = "Do you want to convert C to F, or C to K?";
txtAns1.Visible = false;
sub1.Visible = false;
q1.Visible = false;
}
else if (f.Contains(ans1))
{
para.Text = "";
txtAns2.Visible = true;
sub2.Visible = true;
q2.Visible = true;
q2.Text = "Do you want to convert F to C, or F to K?";
txtAns1.Visible = false;
sub1.Visible = false;
q1.Visible = false;
}
else if (k.Contains(ans1))
{
para.Text = "";
txtAns2.Visible = true;
sub2.Visible = true;
q2.Visible = true;
q2.Text = "Do you want to convert K to C, or K to F?";
txtAns1.Visible = false;
sub1.Visible = false;
q1.Visible = false;
}
else
{
para.Text = "Invalid input. Please enter Kelvin, Fahrenheit, or Celsius.";
}
}
private void Q2()
{
string get2 = txtAns2.Text;
string ans2 = get2.ToLower();
string[] array = { "cf", "ck", "fc", "fk", "kc", "kf" };
if (ans2 == array[0])
{
para2.Text = "";
txtAns3.Visible = true;
sub3.Visible = true;
q3.Visible = true;
q3.Text = "Please input the degree number you would like to convert: ";
txtAns2.Visible = false;
sub2.Visible = false;
q2.Visible = false;
ConvCtoF();
}
else if (ans2 == array[1])
{
para2.Text = "";
txtAns3.Visible = true;
sub3.Visible = true;
q3.Visible = true;
q3.Text = "Please input the degree number you would like to convert: ";
txtAns2.Visible = false;
sub2.Visible = false;
q2.Visible = false;
ConvCtoK();
}
else if (ans2 == array[2])
{
para2.Text = "";
txtAns3.Visible = true;
sub3.Visible = true;
q3.Visible = true;
q3.Text = "Please input the degree number you would like to convert: ";
txtAns2.Visible = false;
sub2.Visible = false;
q2.Visible = false;
ConvFtoC();
}
else if (ans2 == array[3])
{
para2.Text = "";
txtAns3.Visible = true;
sub3.Visible = true;
q3.Visible = true;
q3.Text = "Please input the degree number you would like to convert: ";
txtAns2.Visible = false;
sub2.Visible = false;
q2.Visible = false;
ConvFtoK();
}
else if (ans2 == array[4])
{
para2.Text = "";
txtAns3.Visible = true;
sub3.Visible = true;
q3.Visible = true;
q3.Text = "Please input the degree number you would like to convert: ";
txtAns2.Visible = false;
sub2.Visible = false;
q2.Visible = false;
ConvKtoC();
}
else if (ans2 == array[5])
{
para2.Text = "";
txtAns3.Visible = true;
sub3.Visible = true;
q3.Visible = true;
q3.Text = "Please input the degree number you would like to convert: ";
txtAns2.Visible = false;
sub2.Visible = false;
q2.Visible = false;
ConvKtoF();
}
else
{
para2.Text = "Invalid input. Please put something similar to the following: CF, CK, FC, or FK.";
}
}
private void ConvCtoF()
{
string get3 = txtAns3.Text;
if (float.TryParse(get3, out float ans3))
{
double v = (ans3 * 1.8) + 32;
double vFin = Math.Round(v);
para3.Text = $"The temperature from Celsius to Fahrenheit is: {vFin}";
}
}
private void ConvCtoK()
{
string get3 = txtAns3.Text;
if (float.TryParse(get3, out float ans3))
{
double v = ans3 + 273.15;
double vFin = Math.Round(v);
para3.Text = $"The temperature from Celsius to Fahrenheit is: {vFin}";
}
}
private void ConvFtoC()
{
string get3 = txtAns3.Text;
if (float.TryParse(get3, out float ans3))
{
double v = (ans3 - 32) / 1.8;
double vFin = Math.Round(v);
para3.Text = $"The temperature from Celsius to Fahrenheit is: {vFin}";
}
}
private void ConvFtoK()
{
string get3 = txtAns3.Text;
if (float.TryParse(get3, out float ans3))
{
double v = (ans3 - 32) * 5/9 + 273.15;
double vFin = Math.Round(v);
para3.Text = $"The temperature from Celsius to Fahrenheit is: {vFin}";
}
}
private void ConvKtoC()
{
string get3 = txtAns3.Text;
if (float.TryParse(get3, out float ans3))
{
double v = ans3 - 273.15;
double vFin = Math.Round(v);
para3.Text = $"The temperature from Celsius to Fahrenheit is: {vFin}";
}
}
private void ConvKtoF()
{
string get3 = txtAns3.Text;
if (float.TryParse(get3, out float ans3))
{
double v = (ans3 - 273.15) * 9/5 + 32;
double vFin = Math.Round(v);
para3.Text = $"The temperature from Celsius to Fahrenheit is: {vFin}";
}
}
}
}