输入长方体的长宽高并把它显示出来C#程序
类的定义与操作
运行界面
程序代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows .Forms ;
namespace WindowsFormsApplication4
{
class S
{
private double a;
private double b;
private double c;
public double A
{
get { return a; }
set
{
if (value
MessageBox.Show("此长方体的长设置错误!"); else
a = value;
}
}
public double B
{
get { return b; }
set
{
if (value
MessageBox.Show("此长方体的宽设置错误!"); else
b = value;
}
}
public double C
{
get { return c; }
set
{
if (value
MessageBox.Show("此长方体的高设置错误!"); else
c = value;
}
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
S s1 = new S();
private void button1_Click(object sender, EventArgs e)
{
s1.A = Convert.ToDouble(textBox1.Text); s1.B = Convert.ToDouble(textBox2.Text); s1.C = Convert.ToDouble(textBox3.Text); MessageBox.Show("设置成功!");
}
private void button2_Click(object sender, EventArgs e) {
textBox6.Text = s1.A.ToString();
textBox5.Text = s1.B.ToString();
textBox4.Text = s1.C.ToString();
}
}
}