C# 设计一个求圆面积窗体 当用户输入半径为非数字内容时弹出消息框,Label,TextBox,Button控件各2个。
label1~text为【半径为】,label2~text为【面积为】,Button1为【计算】,Button2为【退出】消息框内容为【请输入内容】~求代码~!!!!...
label1~text为【半径为】,label2~text为【面积为】,Button1为【计算】,Button2为【退出】 消息框内容为【请输入内容】
~求代码~!!!! 展开
~求代码~!!!! 展开
2个回答
展开全部
控件就按照你给的这六个 ,分别为label1, label2, textBox1, textBox2, button1, button2
public Form1()
{
InitializeComponent();
label1.Text = "半径为:";
label2.Text = "面积为:";
button1.Text = "计算";
button2.Text = "退出";
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text.Trim() != ""){
try
{
double r = Convert.ToDouble(textBox1.Text);
double s = Math.PI * r * r;
textBox2.Text = s.ToString();
}
catch (Exception ex)
{
MessageBox.Show("请输入正确的数值作为半径!");
}
}
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
Application.Exit();
}
public Form1()
{
InitializeComponent();
label1.Text = "半径为:";
label2.Text = "面积为:";
button1.Text = "计算";
button2.Text = "退出";
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text.Trim() != ""){
try
{
double r = Convert.ToDouble(textBox1.Text);
double s = Math.PI * r * r;
textBox2.Text = s.ToString();
}
catch (Exception ex)
{
MessageBox.Show("请输入正确的数值作为半径!");
}
}
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
Application.Exit();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询