回答編集履歴
1
変換の値を理解します。
test
CHANGED
@@ -27,3 +27,301 @@
|
|
27
27
|
|
28
28
|
|
29
29
|
ありがとうございます。
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
```ここに言語を入力
|
34
|
+
|
35
|
+
コード
|
36
|
+
|
37
|
+
using System;
|
38
|
+
|
39
|
+
using System.Collections.Generic;
|
40
|
+
|
41
|
+
using System.ComponentModel;
|
42
|
+
|
43
|
+
using System.Data;
|
44
|
+
|
45
|
+
using System.Drawing;
|
46
|
+
|
47
|
+
using System.Linq;
|
48
|
+
|
49
|
+
using System.Text;
|
50
|
+
|
51
|
+
using System.Threading.Tasks;
|
52
|
+
|
53
|
+
using System.Windows.Forms;
|
54
|
+
|
55
|
+
using System.Collections;
|
56
|
+
|
57
|
+
using System.Runtime.InteropServices;
|
58
|
+
|
59
|
+
using System.Threading;
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
namespace MISSION9
|
66
|
+
|
67
|
+
{
|
68
|
+
|
69
|
+
public partial class Form1 : Form
|
70
|
+
|
71
|
+
{
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
public Form1()
|
80
|
+
|
81
|
+
{
|
82
|
+
|
83
|
+
InitializeComponent();
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
}
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
protected double GetAB() //두점 사이의 거리 구하는 함수 (클라스 안에 함수 만들어서 사용가능, 따로 클라스 만들 필요 없음.)
|
92
|
+
|
93
|
+
{
|
94
|
+
|
95
|
+
double x, y, x1, y1;
|
96
|
+
|
97
|
+
string xValue = textBox1.Text;
|
98
|
+
|
99
|
+
x = Convert.ToDouble(xValue); //convert를 사용해서 형 변환하기
|
100
|
+
|
101
|
+
// x = Convert.ToInt32(textBox1.Text); //double계산 한것을 int로 캐스팅 하면 안되는 코딩
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
string yValue = textBox2.Text; //yValue변수 안에 textBox2.text의 텍스트를 받아온다.
|
106
|
+
|
107
|
+
y = Convert.ToDouble(yValue); //yValue의 값을 y에 double형으로 반환해 준다.
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
string x1Value = textBox3.Text;
|
112
|
+
|
113
|
+
x1 = Convert.ToDouble(x1Value);
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
string y1Value = textBox4.Text;
|
118
|
+
|
119
|
+
y1 = Convert.ToDouble(y1Value);
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
double distance = Math.Sqrt((x1 - x) * (x1 - x) + (y1 - y) * (y1 - y)); //double distance변수에 두점사이의 거리를 구하는 식을 만들어 준다.
|
124
|
+
|
125
|
+
//sqrt(제곱근을 반환)
|
126
|
+
|
127
|
+
return (int)distance; //return 값은 int
|
128
|
+
|
129
|
+
}
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
protected double GetBC() //DelegateFunc 괄호 안에 선언 하면 안된다.
|
134
|
+
|
135
|
+
{
|
136
|
+
|
137
|
+
double x1, y1, x2, y2; // 이렇게 따로 함수 안에 선언을 해줘야 된다.
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
string x1Value = textBox3.Text;
|
142
|
+
|
143
|
+
x1 = Convert.ToDouble(x1Value);
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
string y1Value = textBox4.Text;
|
148
|
+
|
149
|
+
y1 = Convert.ToDouble(y1Value);
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
string x2Value = textBox5.Text;
|
154
|
+
|
155
|
+
x2 = Convert.ToDouble(x2Value);
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
string y2Value = textBox6.Text;
|
160
|
+
|
161
|
+
y2 = Convert.ToDouble(y2Value);
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
double distance1 = Math.Sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
return (int)distance1;
|
170
|
+
|
171
|
+
}
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
protected double GetAC()
|
176
|
+
|
177
|
+
{
|
178
|
+
|
179
|
+
double x, y, x2, y2;
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
string x2Value = textBox5.Text;
|
184
|
+
|
185
|
+
x2 = Convert.ToDouble(x2Value);
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
string y2Value = textBox6.Text;
|
190
|
+
|
191
|
+
y2 = Convert.ToDouble(y2Value);
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
string xValue = textBox1.Text;
|
196
|
+
|
197
|
+
x = Convert.ToDouble(xValue);
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
string yValue = textBox2.Text;
|
202
|
+
|
203
|
+
y = Convert.ToDouble(yValue);
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
double distance2 = Math.Sqrt((x2 - x) * (x2 - x) + (y2 - y) * (y2 - y));
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
return (int)distance2;
|
212
|
+
|
213
|
+
}
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
private void button1_Click(object sender, EventArgs e)
|
218
|
+
|
219
|
+
{
|
220
|
+
|
221
|
+
string str = textBox1.Text; //str에 textbox1의 입력 값을 넣는다. (button안에서 한번더 반환해 주어야 된다. )
|
222
|
+
|
223
|
+
double aaa = Convert.ToDouble(str); //str값을 aaa에 double값으로 반환한다.
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
string str1 = textBox2.Text;
|
228
|
+
|
229
|
+
double bbb = Convert.ToDouble(str1);
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
string str2 = textBox3.Text;
|
234
|
+
|
235
|
+
double ccc = Convert.ToDouble(str2);
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
string str3 = textBox4.Text;
|
240
|
+
|
241
|
+
double ddd = Convert.ToDouble(str3);
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
string str4 = textBox5.Text;
|
246
|
+
|
247
|
+
double eee = Convert.ToDouble(str4);
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
string str5 = textBox6.Text;
|
252
|
+
|
253
|
+
double fff = Convert.ToDouble(str5);
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
label15.Text = GetAB().ToString(); //label15에 GetAB함수를 문자열로 바꿔준다.
|
260
|
+
|
261
|
+
label16.Text = GetBC().ToString(); //어차피 함수 안에서 읽어 줬기 때문에 GetAB()괄호 안에 또 지정해 줄 필요가 없다.
|
262
|
+
|
263
|
+
label17.Text = GetAC().ToString();
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
//label16.Text = GetBC(2, 3, 1, 5); //이렇게 숫를 넣어주어야 되지만 위에 처럼 반환 값을 입력해준다.
|
270
|
+
|
271
|
+
//label17.Text = GetAC(label17.Text); //메소드, 함수 사용법 다시 훓기
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
}
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
private void pictureBox1_Click(object sender, EventArgs e) //그냥 삼각형 출력하기 위해서 한것.
|
282
|
+
|
283
|
+
{
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
Bitmap canvas = new Bitmap(pictureBox1.Width, pictureBox1.Height); // 렌더링 대상으로하는 Image 객체를 만드는
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
Graphics g = Graphics.FromImage(canvas); // Image 객체의 Graphics 객체를 만들
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
Point[] ps = { new Point (0, 0), // 직선으로 연결하는 점의 배열을 만들
|
296
|
+
|
297
|
+
new Point (190, 90),
|
298
|
+
|
299
|
+
new Point (120, 140) };
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
g.DrawPolygon(Pens.Black, ps); // 다각형 그리기
|
304
|
+
|
305
|
+
g.Dispose(); // 리소스를 해제
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
pictureBox1.Image = canvas; // PictureBox1에 표시
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
}
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
}
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
}
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
```
|