回答編集履歴
1
変換の値を理解します。
answer
CHANGED
@@ -12,4 +12,153 @@
|
|
12
12
|
|
13
13
|
必要ないキャステイングを削除してGetAB, GetBC, GetAC内をもう一度変換しました!
|
14
14
|
|
15
|
-
ありがとうございます。
|
15
|
+
ありがとうございます。
|
16
|
+
|
17
|
+
```ここに言語を入力
|
18
|
+
コード
|
19
|
+
using System;
|
20
|
+
using System.Collections.Generic;
|
21
|
+
using System.ComponentModel;
|
22
|
+
using System.Data;
|
23
|
+
using System.Drawing;
|
24
|
+
using System.Linq;
|
25
|
+
using System.Text;
|
26
|
+
using System.Threading.Tasks;
|
27
|
+
using System.Windows.Forms;
|
28
|
+
using System.Collections;
|
29
|
+
using System.Runtime.InteropServices;
|
30
|
+
using System.Threading;
|
31
|
+
|
32
|
+
|
33
|
+
namespace MISSION9
|
34
|
+
{
|
35
|
+
public partial class Form1 : Form
|
36
|
+
{
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
public Form1()
|
41
|
+
{
|
42
|
+
InitializeComponent();
|
43
|
+
|
44
|
+
}
|
45
|
+
|
46
|
+
protected double GetAB() //두점 사이의 거리 구하는 함수 (클라스 안에 함수 만들어서 사용가능, 따로 클라스 만들 필요 없음.)
|
47
|
+
{
|
48
|
+
double x, y, x1, y1;
|
49
|
+
string xValue = textBox1.Text;
|
50
|
+
x = Convert.ToDouble(xValue); //convert를 사용해서 형 변환하기
|
51
|
+
// x = Convert.ToInt32(textBox1.Text); //double계산 한것을 int로 캐스팅 하면 안되는 코딩
|
52
|
+
|
53
|
+
string yValue = textBox2.Text; //yValue변수 안에 textBox2.text의 텍스트를 받아온다.
|
54
|
+
y = Convert.ToDouble(yValue); //yValue의 값을 y에 double형으로 반환해 준다.
|
55
|
+
|
56
|
+
string x1Value = textBox3.Text;
|
57
|
+
x1 = Convert.ToDouble(x1Value);
|
58
|
+
|
59
|
+
string y1Value = textBox4.Text;
|
60
|
+
y1 = Convert.ToDouble(y1Value);
|
61
|
+
|
62
|
+
double distance = Math.Sqrt((x1 - x) * (x1 - x) + (y1 - y) * (y1 - y)); //double distance변수에 두점사이의 거리를 구하는 식을 만들어 준다.
|
63
|
+
//sqrt(제곱근을 반환)
|
64
|
+
return (int)distance; //return 값은 int
|
65
|
+
}
|
66
|
+
|
67
|
+
protected double GetBC() //DelegateFunc 괄호 안에 선언 하면 안된다.
|
68
|
+
{
|
69
|
+
double x1, y1, x2, y2; // 이렇게 따로 함수 안에 선언을 해줘야 된다.
|
70
|
+
|
71
|
+
string x1Value = textBox3.Text;
|
72
|
+
x1 = Convert.ToDouble(x1Value);
|
73
|
+
|
74
|
+
string y1Value = textBox4.Text;
|
75
|
+
y1 = Convert.ToDouble(y1Value);
|
76
|
+
|
77
|
+
string x2Value = textBox5.Text;
|
78
|
+
x2 = Convert.ToDouble(x2Value);
|
79
|
+
|
80
|
+
string y2Value = textBox6.Text;
|
81
|
+
y2 = Convert.ToDouble(y2Value);
|
82
|
+
|
83
|
+
double distance1 = Math.Sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
|
84
|
+
|
85
|
+
return (int)distance1;
|
86
|
+
}
|
87
|
+
|
88
|
+
protected double GetAC()
|
89
|
+
{
|
90
|
+
double x, y, x2, y2;
|
91
|
+
|
92
|
+
string x2Value = textBox5.Text;
|
93
|
+
x2 = Convert.ToDouble(x2Value);
|
94
|
+
|
95
|
+
string y2Value = textBox6.Text;
|
96
|
+
y2 = Convert.ToDouble(y2Value);
|
97
|
+
|
98
|
+
string xValue = textBox1.Text;
|
99
|
+
x = Convert.ToDouble(xValue);
|
100
|
+
|
101
|
+
string yValue = textBox2.Text;
|
102
|
+
y = Convert.ToDouble(yValue);
|
103
|
+
|
104
|
+
double distance2 = Math.Sqrt((x2 - x) * (x2 - x) + (y2 - y) * (y2 - y));
|
105
|
+
|
106
|
+
return (int)distance2;
|
107
|
+
}
|
108
|
+
|
109
|
+
private void button1_Click(object sender, EventArgs e)
|
110
|
+
{
|
111
|
+
string str = textBox1.Text; //str에 textbox1의 입력 값을 넣는다. (button안에서 한번더 반환해 주어야 된다. )
|
112
|
+
double aaa = Convert.ToDouble(str); //str값을 aaa에 double값으로 반환한다.
|
113
|
+
|
114
|
+
string str1 = textBox2.Text;
|
115
|
+
double bbb = Convert.ToDouble(str1);
|
116
|
+
|
117
|
+
string str2 = textBox3.Text;
|
118
|
+
double ccc = Convert.ToDouble(str2);
|
119
|
+
|
120
|
+
string str3 = textBox4.Text;
|
121
|
+
double ddd = Convert.ToDouble(str3);
|
122
|
+
|
123
|
+
string str4 = textBox5.Text;
|
124
|
+
double eee = Convert.ToDouble(str4);
|
125
|
+
|
126
|
+
string str5 = textBox6.Text;
|
127
|
+
double fff = Convert.ToDouble(str5);
|
128
|
+
|
129
|
+
|
130
|
+
label15.Text = GetAB().ToString(); //label15에 GetAB함수를 문자열로 바꿔준다.
|
131
|
+
label16.Text = GetBC().ToString(); //어차피 함수 안에서 읽어 줬기 때문에 GetAB()괄호 안에 또 지정해 줄 필요가 없다.
|
132
|
+
label17.Text = GetAC().ToString();
|
133
|
+
|
134
|
+
|
135
|
+
//label16.Text = GetBC(2, 3, 1, 5); //이렇게 숫를 넣어주어야 되지만 위에 처럼 반환 값을 입력해준다.
|
136
|
+
//label17.Text = GetAC(label17.Text); //메소드, 함수 사용법 다시 훓기
|
137
|
+
|
138
|
+
}
|
139
|
+
|
140
|
+
|
141
|
+
private void pictureBox1_Click(object sender, EventArgs e) //그냥 삼각형 출력하기 위해서 한것.
|
142
|
+
{
|
143
|
+
|
144
|
+
Bitmap canvas = new Bitmap(pictureBox1.Width, pictureBox1.Height); // 렌더링 대상으로하는 Image 객체를 만드는
|
145
|
+
|
146
|
+
Graphics g = Graphics.FromImage(canvas); // Image 객체의 Graphics 객체를 만들
|
147
|
+
|
148
|
+
Point[] ps = { new Point (0, 0), // 직선으로 연결하는 점의 배열을 만들
|
149
|
+
new Point (190, 90),
|
150
|
+
new Point (120, 140) };
|
151
|
+
|
152
|
+
g.DrawPolygon(Pens.Black, ps); // 다각형 그리기
|
153
|
+
g.Dispose(); // 리소스를 해제
|
154
|
+
|
155
|
+
pictureBox1.Image = canvas; // PictureBox1에 표시
|
156
|
+
|
157
|
+
}
|
158
|
+
|
159
|
+
|
160
|
+
}
|
161
|
+
|
162
|
+
}
|
163
|
+
|
164
|
+
```
|