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;
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 linhongjie
{
public partial class Form1 : Form
{
public partial class Form1 : Form
{
double a = 0;
double b = 0;
bool c = false;
String d;
public Form1()
{
InitializeComponent();
}
double a = 0;
double b = 0;
bool c = false;
String d;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
{
}
private void button14_Click(object sender, EventArgs e) //对应数字0,单独处理
{
if (c == true) {
textBox1.Text = "";
c = false;
}
textBox1.Text += "0";
if (d == "/") {
textBox1.Clear();
MessageBox.Show("除数不可为0", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
{
if (c == true) {
textBox1.Text = "";
c = false;
}
textBox1.Text += "0";
if (d == "/") {
textBox1.Clear();
MessageBox.Show("除数不可为0", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
//定义一个传递数字的方法
private void button5_Click(object sender, EventArgs e)
{
buttonOperation_Click("*");
}
private void buttonNo_Click(int num) {
if(c == true){
textBox1.Text = "";
c = false;
}
if (textBox1.Text == "0")
{ //当第一个数字为0时,清零再显示其他数字
textBox1.Text = "";
}
textBox1.Text += num;
}
//对应数字键
//对应数字键
private void button1_Click(object sender, EventArgs e)
{
buttonNo_Click(1);
}
{
buttonNo_Click(1);
}
private void button13_Click(object sender, EventArgs e)
{
buttonNo_Click(4);
}
{
buttonNo_Click(4);
}
private void button10_Click(object sender, EventArgs e)
{
buttonNo_Click(2);
}
{
buttonNo_Click(2);
}
private void button4_Click(object sender, EventArgs e)
{
buttonNo_Click(3);
}
{
buttonNo_Click(3);
}
private void button9_Click(object sender, EventArgs e)
{
buttonNo_Click(5);
}
{
buttonNo_Click(5);
}
private void button2_Click(object sender, EventArgs e)
{
buttonNo_Click(6);
}
{
buttonNo_Click(6);
}
private void button12_Click(object sender, EventArgs e)
{
buttonNo_Click(7);
}
{
buttonNo_Click(7);
}
private void button8_Click(object sender, EventArgs e)
{
buttonNo_Click(8);
}
{
buttonNo_Click(8);
}
private void button20_Click(object sender, EventArgs e)
{
buttonNo_Click(9);
}
{
buttonNo_Click(9);
}
//定义一个传递符号的方法
//对应符号键
private void buttonOperation_Click(String s) {
c = true;
b = double.Parse(textBox1.Text);
d = s;
}
private void button19_Click(object sender, EventArgs e)
{
buttonOperation_Click("+");
}
//对应符号键
private void buttonOperation_Click(String s) {
c = true;
b = double.Parse(textBox1.Text);
d = s;
}
private void button19_Click(object sender, EventArgs e)
{
buttonOperation_Click("+");
}
private void button3_Click(object sender, EventArgs e)
{
buttonOperation_Click("-");
}
{
buttonOperation_Click("-");
}
private void button6_Click(object sender, EventArgs e)
{
buttonOperation_Click("/");
}
{
buttonOperation_Click("/");
}
private void button15_Click(object sender, EventArgs e)
{
buttonOperation_Click("x2");
}
{
buttonOperation_Click("x2");
}
private void button16_Click(object sender, EventArgs e)
{
buttonOperation_Click("sqrt");
}
{
buttonOperation_Click("sqrt");
}
private void button17_Click(object sender, EventArgs e)
{
buttonOperation_Click("log");
}
{
buttonOperation_Click("log");
}
private void button18_Click(object sender, EventArgs e)
{
buttonOperation_Click("ln");
}
{
buttonOperation_Click("ln");
}
private void button7_Click(object sender, EventArgs e) //对应=键
{
switch (d)
{
case "+": a = b + double.Parse(textBox1.Text); break;
case "-": a = b - double.Parse(textBox1.Text); break;
case "*": a = b* double.Parse(textBox1.Text); break;
case "/": a = b / double.Parse(textBox1.Text); break;
case "x2": a = b* double.Parse(textBox1.Text); break;
case "sqrt": a = Math.Sqrt(b ); break;
case "log": a = Math.Log(double.Parse(textBox1.Text),b ); break;
case "ln": a = Math.Log(b, Math.E); break;
}
textBox1.Text = a + "";
c = true;
}
{
switch (d)
{
case "+": a = b + double.Parse(textBox1.Text); break;
case "-": a = b - double.Parse(textBox1.Text); break;
case "*": a = b* double.Parse(textBox1.Text); break;
case "/": a = b / double.Parse(textBox1.Text); break;
case "x2": a = b* double.Parse(textBox1.Text); break;
case "sqrt": a = Math.Sqrt(b ); break;
case "log": a = Math.Log(double.Parse(textBox1.Text),b ); break;
case "ln": a = Math.Log(b, Math.E); break;
}
textBox1.Text = a + "";
c = true;
}
private void button11_Click(object sender, EventArgs e)
{
textBox1.Clear();
}
{
textBox1.Clear();
}
}
}
}
还不清楚的话可以借鉴于:http://blog.csdn.net/sagittarius_bear/article/details/52066723
吾在其基础上进行算法的优化,以及优化了几个bug