c#建立一个windows应用程序 实现计算三角行 矩形的以及圆的面积 与周长.
2013-05-29
展开全部
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("不能构成圆形");
}
}
}
}
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("不能构成圆形");
}
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |