c#建立一个windows应用程序 实现计算三角行 矩形的以及圆的面积 与周长.

如题所述

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;
using System.IO;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{

} private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
label1.Visible=label2.Visible=label3.Visible=textBox1.Visible=textBox2.Visible=textBox3.Visible = true;
label1.Text = "第一条边长";
label2.Text = "第二条边长";
label3.Text = "第三条边长";
} private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
label3.Visible = textBox3.Visible = false;
label1.Text = "长";
label2.Text = "高";
} private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
label2.Visible = label3.Visible= textBox2.Visible = textBox3.Visible =false;
label1.Text = "半径";
} private void button1_Click(object sender, EventArgs e)
{
if (radioButton1.Checked)
{ double a = int.Parse(textBox1.Text.ToString().Trim());
double b = int.Parse(textBox2.Text.ToString().Trim());
double c = int.Parse(textBox3.Text.ToString().Trim());
double s = 0;
if (a + b > c && a + c > b && b + c > a&&a>0&&b>0&&c>0)
{
string p = "";s = (a + b + c) / 2;
p = string.Format("三角形周长:{0}\t三角形面积:{1}", a + b + c, s);
MessageBox.Show(p);
}
else MessageBox.Show("不能构成三角形");
}
else if (radioButton2.Checked)
{
double a = int.Parse(textBox1.Text.ToString().Trim());
double b = int.Parse(textBox2.Text.ToString().Trim());
if (a > 0 && b > 0 )
{
string p = "";
p = string.Format("矩形周长:{0}\t矩形面积:{1}", 2 * (a + b), a * b);
MessageBox.Show(p);
}
else MessageBox.Show("不能构成矩形");
}
else
{ double a = int.Parse(textBox1.Text.ToString().Trim());
if (a > 0)
{
string p = "";
p = string.Format("圆形周长:{0}\t圆形面积:{1}", 2*Math.PI*a, Math.PI*a*a);
MessageBox.Show(p);
}
else MessageBox.Show("不能构成圆形");
}
}
}
}
温馨提示:答案为网友推荐,仅供参考
相似回答