比如1+2*3会先算2*3再+1,大家帮帮忙哦
还是发代码上来吧
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace 计算器
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
bool x=true;
string ch;
double number1=0,number2=0,sum;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Button button5;
private System.Windows.Forms.Button button6;
private System.Windows.Forms.Button button7;
public System.Windows.Forms.Button button8;
private System.Windows.Forms.Button button9;
private System.Windows.Forms.Button button10;
private System.Windows.Forms.Button button11;
private System.Windows.Forms.Button button12;
private System.Windows.Forms.Button button13;
private System.Windows.Forms.Button button14;
private System.Windows.Forms.Button button15;
private System.Windows.Forms.Button button16;
private System.Windows.Forms.Button button17;
private System.Windows.Forms.Button button18;
private System.Windows.Forms.Button button19;
private System.Windows.Forms.Button button20;
private System.Windows.Forms.Button button21;
private System.Windows.Forms.Button button22;
private System.Windows.Forms.Button button23;
private System.Windows.Forms.Button button24;
private System.Windows.Forms.Button button25;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button24_Click(object sender, System.EventArgs e)
{
double x,y;
x = double.Parse (textBox1.Text );
y=x-2*x;
textBox1.Text = y.ToString () ;
}
private void button21_Click(object sender, System.EventArgs e)
{
number1 = double.Parse (textBox1.Text );
ch = button21.Text ;
x=true;
}
private void button22_Click(object sender, System.EventArgs e)
{
number1 = double .Parse (textBox1.Text) ;
if(number1<0)
{
textBox1.Text ="不能求负数的平方根!";
}
else if(number1==0)
{
textBox1.Text = number1.ToString ();
}
else
{
textBox1.Text = Math.Sqrt (number1).ToString ();
}
}
private void button23_Click(object sender, System.EventArgs e)
{
textBox1.Clear ();
double a=0;
x=true;
textBox1.Text = a.ToString ();
}
private void button20_Click(object sender, System.EventArgs e)
{
number1 = double.Parse (textBox1.Text );
sum = number1*number1;
textBox1.Text = sum.ToString ();
}
private void button19_Click(object sender, System.EventArgs e)
{
number1 = double.Parse (textBox1.Text) ;
sum=1;
for(int i =1;i<=number1;i++)
{
sum *=i;
}
textBox1.Text = sum.ToString ();
}
private void button18_Click(object sender, System.EventArgs e)
{
this.Close ();
}
private void button17_Click(object sender, System.EventArgs e)
{
number1=0;
number2=0;
ch="";
sum=0;
x=true;
textBox1.Clear ();
// textBox1.Focus ();
textBox1.Text = number1.ToString ();
}
private void button16_Click(object sender, System.EventArgs e)
{
if(ch!="")
{
if(ch == button12.Text )
{
number2 = double.Parse (textBox1.Text );
textBox1.Clear ();
sum = number1+number2;
textBox1.Text = sum.ToString ();
number1=double.Parse (textBox1.Text );
}
else if(ch == button13.Text )
{
number2 = double.Parse (textBox1.Text );
textBox1.Clear ();
sum = number1-number2;
textBox1.Text = sum.ToString ();
number1=double.Parse (textBox1.Text );
}
else if(ch == button14.Text )
{
number2 = double.Parse (textBox1.Text );
textBox1.Clear ();
sum = number1*number2;
textBox1.Text = sum.ToString ();
number1=double.Parse (textBox1.Text );
}
else if(ch == button16.Text )
{
number2 = double.Parse (textBox1.Text );
textBox1.Clear ();
if(number2==0)
{
textBox1.Text ="除数不能为零!";
sum =0;
}
else
{
sum = number1/number2;
textBox1.Text = sum.ToString ();
number1=double.Parse (textBox1.Text );
}
}
}
number1 = double.Parse (textBox1.Text );
x=true;
ch = button16.Text ;
}
private void button14_Click(object sender, System.EventArgs e)
{
if(ch =="")
{
number1=double.Parse (textBox1.Text );
textBox1.Text = number1.ToString ();
}
if(ch == button12.Text )
{
number2 = double.Parse (textBox1.Text );
textBox1.Clear ();
sum = number1+number2;
textBox1.Text = sum.ToString ();
number1=double.Parse (textBox1.Text );
}
else if(ch == button13.Text )
{
number2 = double.Parse (textBox1.Text );
textBox1.Clear ();
sum = number1-number2;
textBox1.Text = sum.ToString ();
number1=double.Parse (textBox1.Text );
}
else if(ch == button14.Text )
{
number2 = double.Parse (textBox1.Text );
textBox1.Clear ();
sum = number1*number2;
textBox1.Text = sum.ToString ();
number1=double.Parse (textBox1.Text );
}
else if(ch == button16.Text )
{
number2 = double.Parse (textBox1.Text );
textBox1.Clear ();
if(number2==0)
{
textBox1.Text ="除数不能为零!";
sum =0;
}
else
{
sum = number1/number2;
textBox1.Text = sum.ToString ();
number1=double.Parse (textBox1.Text );
}
}
number1 = double.Parse (textBox1.Text) ;
x=true;
ch = button14.Text ; ;
}
private void button13_Click(object sender, System.EventArgs e)
{
if(ch!="")
{
if(ch == button12.Text )
{
number2 = double.Parse (textBox1.Text );
textBox1.Clear ();
sum = number1+number2;
textBox1.Text = sum.ToString ();
number1=double.Parse (textBox1.Text );
}
else if(ch == button13.Text )
{
number2 = double.Parse (textBox1.Text );
textBox1.Clear ();
sum = number1-number2;
textBox1.Text = sum.ToString ();
number1=double.Parse (textBox1.Text );
}
else if(ch == button14.Text )
{
number2 = double.Parse (textBox1.Text );
textBox1.Clear ();
sum = number1*number2;
textBox1.Text = sum.ToString ();
number1=double.Parse (textBox1.Text );
}
else if(ch == button16.Text )
{
number2 = double.Parse (textBox1.Text );
textBox1.Clear ();
if(number2==0)
{
textBox1.Text ="除数不能为零!";
sum =0;
}
else
{
sum = number1/number2;
textBox1.Text = sum.ToString ();
number1=double.Parse (textBox1.Text );
}
}
}
number1 = double.Parse (textBox1.Text );
x=true;
ch = button13.Text ;
}
private void button12_Click(object sender, System.EventArgs e)
{
if(ch!="")
{
if(ch == button12.Text )
{
number2 = double.Parse (textBox1.Text );
textBox1.Clear ();
sum = number1+number2;
textBox1.Text = sum.ToString ();
number1=double.Parse (textBox1.Text );
}
else if(ch == button13.Text )
{
number2 = double.Parse (textBox1.Text );
textBox1.Clear ();
sum = number1-number2;
textBox1.Text = sum.ToString ();
number1=double.Parse (textBox1.Text );
}
else if(ch == button14.Text )
{
number2 = double.Parse (textBox1.Text );
textBox1.Clear ();
sum = number1*number2;
textBox1.Text = sum.ToString ();
number1=double.Parse (textBox1.Text );
}
else if(ch == button16.Text )
{
number2 = double.Parse (textBox1.Text );
textBox1.Clear ();
if(number2==0)
{
textBox1.Text ="除数不能为零!";
sum =0;
}
else
{
sum = number1/number2;
textBox1.Text = sum.ToString ();
number1=double.Parse (textBox1.Text );
}
}
}
number1 = double.Parse (textBox1.Text );
ch = button12.Text ;
x = true;
}
private void button11_Click(object sender, System.EventArgs e)
{
if(x==true)
{
textBox1.Clear ();
x=false;
}
textBox1.Text += button11.Text ;
}
private void button10_Click(object sender, System.EventArgs e)
{
if(x==true)
{
textBox1.Clear ();
x=false;
}
textBox1.Text += button10.Text;
}
private void button9_Click(object sender, System.EventArgs e)
{
if(x==true)
{
textBox1.Clear ();
x=false;
}
textBox1.Text += button9.Text ;
}
private void button8_Click(object sender, System.EventArgs e)
{
if(x==true)
{
textBox1.Clear ();
x=false;
}
textBox1.Text +=button8.Text ;
}
private void button7_Click(object sender, System.EventArgs e)
{
if(x==true)
{
textBox1.Clear ();
x=false;
}
textBox1.Text += button7.Text ;
}
private void button6_Click(object sender, System.EventArgs e)
{
if(x==true)
{
textBox1.Clear ();
x=false;
}
textBox1.Text +=button6.Text ;
}
private void button5_Click(object sender, System.EventArgs e)
{
if(x==true)
{
textBox1.Clear ();
x=false;
}
textBox1.Text +=button5.Text ;
}
private void button4_Click(object sender, System.EventArgs e)
{
if(x==true)
{
textBox1.Clear ();
x=false;
}
textBox1.Text +=button4.Text ;
}
private void button3_Click(object sender, System.EventArgs e)
{
if(x==true)
{
textBox1.Clear ();
x=false;
}
textBox1.Text += button3.Text ;
}
private void button2_Click(object sender, System.EventArgs e)
{
if(x==true)
{
textBox1.Clear ();
x=false;
}
textBox1.Text += button2.Text ;
}
private void button1_Click(object sender, System.EventArgs e)
{
if(x==true)
{
textBox1.Clear ();
x=false;
}
textBox1.Text +=button1.Text ;
}
private void Form1_Load()
{
}
}
}