- 设计一个简单的Windows应用程序,在文本框中输入两个点的坐标值,单击“确定”时显示两点之间的距离。
要求定义一个Point类,包括
- 两个私有字段表示两个坐标值
- 一个构造函数通过传入的参数对坐标值初始化。
- 两个只读属性对坐标值的读取。
- 一个方法包含一个Point类对象作为形参计算该对象和自己的距离。
class point
{
private int x;
private int y;
public point(int a,int b) {
x = a;
y = b;
}
public int X
{
get
{
return x;
}
}
public int Y
{
get
{
return y;
}
}
public double longs(point a)
{
double dd;
dd = (a.x - this.x) * (a.x - this.x) + (a.y - this.y) * (a.y - this.y);
dd = Math.Sqrt(dd);
return dd;
}
}
private void button6_Click(object sender, EventArgs e)
{
this.Close();
}
private void button5_Click(object sender, EventArgs e)
{
int x1 =Convert.ToInt32(textBox1.Text);
int y1 = Convert.ToInt32(textBox4.Text);
int x2 = Convert.ToInt32(textBox2.Text);
int y2 = Convert.ToInt32(textBox5.Text);
point a1=new point(x1,y1);
point a2 = new point(x2, y2);
textBox3.Text = Convert.ToString(a1.longs(a2));
}