using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace 计算器
{
public partial class Form6 : Form
{
public Form6()
{
InitializeComponent();
}
//上一个按钮是否是运算符;
//一个面积为50的矩形 求他能形成圆的最大面积
bool iscalc = false;
//1
private void button1_Click_1(object sender, EventArgs e)
{
if (iscalc == true)
{
textBox1.Text = "";
iscalc = false;
}
textBox1.Text += 1;
}
//2
private void button2_Click_1(object sender, EventArgs e)
{
if (iscalc == true)
{
textBox1.Text = "";
iscalc = false;
}
textBox1.Text += 2;
}
//3
private void button3_Click_1(object sender, EventArgs e)
{
if (iscalc == true)
{
textBox1.Text = "";
iscalc = false;
}
textBox1.Text += 3;
}
//4
private void button4_Click_1(object sender, EventArgs e)
{
if (iscalc == true)
{
textBox1.Text = "";
iscalc = false;
}
textBox1.Text += 4;
}
//5
private void button5_Click_1(object sender, EventArgs e)
{
if (iscalc == true)
{
textBox1.Text = "";
iscalc = false;
}
textBox1.Text += 5;
}
//6
private void button6_Click_1(object sender, EventArgs e)
{
if (iscalc == true)
{
textBox1.Text = "";
iscalc = false;
}
textBox1.Text += 6;
}
//7
private void button7_Click_1(object sender, EventArgs e)
{
if (iscalc == true)
{
textBox1.Text = "";
iscalc = false;
}
textBox1.Text += 7;
}
//8
private void button8_Click_1(object sender, EventArgs e)
{
if (iscalc == true)
{
textBox1.Text = "";
iscalc = false;
}
textBox1.Text += 8;
}
//9
private void button9_Click_1(object sender, EventArgs e)
{
if (iscalc == true)
{
textBox1.Text = "";
iscalc = false;
}
textBox1.Text += 9;
}
//0
private void button10_Click_1(object sender, EventArgs e)
{
if (iscalc == true)
{
textBox1.Text = "";
iscalc = false;//不改回false时会一直清除数字。
}
textBox1.Text += 0;
}
double num1;
bool isdel = false;
string yunsuan;
double num2;
//+
private void button11_Click_1(object sender, EventArgs e)
{
yunsuan = "+";
isdel = false;
iscalc = true;
if (double.TryParse(textBox1.Text, out num1))
{
num1 = double.Parse(textBox1.Text);
}
else
{
return;
}
}
//-
private void button12_Click_1(object sender, EventArgs e)
{
yunsuan = "-";
isdel = false;
iscalc = true;
if (double.TryParse(textBox1.Text, out num1))
{
num1 = double.Parse(textBox1.Text);
}
else
{
return;
}
}
//*
private void button13_Click_1(object sender, EventArgs e)
{
yunsuan = "*";
isdel = false;
iscalc = true;
if (double.TryParse(textBox1.Text, out num1))
{
num1 = double.Parse(textBox1.Text);
}
else
{
return;
}
}
//÷
private void button14_Click_1(object sender, EventArgs e)
{
yunsuan = "÷";
isdel = false;
iscalc = true;
if (double.TryParse(textBox1.Text, out num1))
{
num1 = double.Parse(textBox1.Text);
}
else
{
return;
}
}
//=
private void button15_Click_1(object sender, EventArgs e)
{
if (double.TryParse(textBox1.Text, out num2))
{
num2 = double.Parse(textBox1.Text);
}
else
{
return;
}
iscalc = true;
//num2 = double.Parse(textBox1.Text);
if (yunsuan == "+")
{
textBox1.Text = (num1 + num2).ToString();
}
if (yunsuan == "-")
{
textBox1.Text = (num1 - num2).ToString();
}
if (yunsuan == "*")
{
textBox1.Text = (num1 * num2).ToString();
}
if (yunsuan == "÷")
{
textBox1.Text = (num1 / num2).ToString();
}
//textBox2.Text = 2*π * textBox2.Text;
}
//.
private void button16_Click_1(object sender, EventArgs e)
{
if (isdel == false)
{
textBox1.Text += ".";
isdel = true;
}
}
//CE
private void button17_Click_1(object sender, EventArgs e)
{
textBox1.Text = "";
isdel = false;
}
//平方
private void button18_Click(object sender, EventArgs e)
{
num1 = double.Parse(textBox1.Text);
textBox1.Text = (Math.Pow(num1, 2)).ToString();
iscalc = true;
}
//cos
private void button19_Click(object sender, EventArgs e)
{
num1 = double.Parse(textBox1.Text);
iscalc = true;
textBox1.Text = (Math.Cos(num1)).ToString();
}
//tan
private void button21_Click(object sender, EventArgs e)
{
num1 = double.Parse(textBox1.Text);
iscalc = true;
textBox1.Text = (Math.Tan(num1)).ToString();
}
//sin
private void button20_Click(object sender, EventArgs e)
{
num1 = double.Parse(textBox1.Text);
iscalc = true;
textBox1.Text = (Math.Sin(num1)).ToString();
}
//Asin
private void button22_Click(object sender, EventArgs e)
{
num1 = double.Parse(textBox1.Text);
iscalc = true;
textBox1.Text = (Math.Asin(num1)).ToString();
}
//圆的周长
private void button23_Click(object sender, EventArgs e)
{
num1 = double.Parse(textBox2.Text);
iscalc = true;
textBox1.Text = (Math.PI*(num1*2)).ToString();
}
//圆的面积
private void button24_Click(object sender, EventArgs e)
{
num1 = double.Parse(textBox2.Text);
iscalc = true;
textBox1.Text = (Math.PI*2*(num1*num1)).ToString();
}
// v^2=2gs; 小球100米处掉落求掉落时大概速度
private void button25_Click(object sender, EventArgs e)
{
textBox1.Text = (Math.Sqrt(2 * 10 * 100)).ToString();
}
}
}
c#简易计算器
最新推荐文章于 2023-03-14 13:50:12 发布