1、 功能看界面就是了, //后台代码C# using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace Calculator2 { public partial class _Default : System.Web.UI.Page { protected void Page_
2、Load(object sender, EventArgs e) { } protected void Compute(object sender, EventArgs e) { Double Pi = Math.PI; Double num1; Double num2; String str1,str2,str3; // Double result; int l
3、en; // Char[] c = { '+', '-', '*', '/' }; if (sender.Equals(BtnEqual)) { str1 = Loadstr1.Text; len = str1.Length; str2 =Loadstr2.Text; str3 = Loadstr3.Text; // char[] strArry =
4、 str1.ToCharArray(); num1 =Convert.ToDouble(str3); num2 = Convert.ToDouble(txtResult .Text); if (txtResult.Text == "") { txtResult.Text = " "; } // num2=con
5、 switch (str1) { case "+": txtResult.Text = Convert.ToString( num2 + num1); break; case "-": txtResult.Text = Convert.ToString( num1 - num2); break; case "*": txtResult.Text = Convert.ToString( num1 * num2); brea
6、k; case "/": if (num2 == 0) txtResult.Text = "除数不能为0"; else txtResult.Text = Convert.ToString(num1 / num2); break; } //num2 = result;
7、 // txtResult.Text = Convert.ToString(num2); } if (sender.Equals(BtnAdd)) { Loadstr1.Text ="+"; Loadstr3.Text = txtResult.Text; txtResult.Text = ""; } if (sender.Equals(BtnSu
8、b)) { Loadstr1.Text ="-"; Loadstr3.Text = txtResult.Text; txtResult.Text = ""; } if (sender.Equals(BtnMul)) { Loadstr1.Text = "*";
9、 Loadstr3.Text = txtResult.Text; txtResult.Text = ""; } if (sender.Equals(BtnDivide)) { Loadstr1.Text = "/"; Loadstr3.Text = txtResult.Text; txtResult.Text =
10、 ""; } if (sender.Equals(Btn1)) { if (txtResult.Text == "0") txtResult.Text = "1"; else txtResult.Text += "1"; Loadstr2.Text = txtResult.Text; } if (sender
11、Equals(Btn2)) { if (txtResult.Text == "0") txtResult.Text = "2"; else txtResult.Text += "2"; Loadstr2.Text = txtResult.Text; } if (sender.Equals(Btn3)) { if
12、 (txtResult.Text == "0") txtResult.Text = "3"; else txtResult.Text += "3"; Loadstr2.Text = txtResult.Text; } if (sender.Equals(Btn4)) { if (txtResult.Text == "0") txt
13、Result.Text = "4"; else txtResult.Text += "4"; Loadstr2.Text = txtResult.Text; } if (sender.Equals(Btn5)) { if (txtResult.Text == "0") txtResult.Text = "5"; else txtResult.Text += "5";
14、 Loadstr2.Text = txtResult.Text; } if (sender.Equals(Btn6)) { if (txtResult.Text == "0") txtResult.Text = "6"; else txtResult.Text += "6"; Loadstr2.Text = txtResult.Text;
15、 } if (sender.Equals(Btn7)) { if (txtResult.Text == "0") txtResult.Text = "7"; else txtResult.Text += "7"; Loadstr2.Text = txtResult.Text; } if (sender.Equals(Btn8)
16、) { if (txtResult.Text == "0") txtResult.Text = "8"; else txtResult.Text += "8"; Loadstr2.Text = txtResult.Text; } if (sender.Equals(Btn9)) { if (txtResult.T
17、ext == "0") txtResult.Text = "9"; else txtResult.Text += "9"; Loadstr2.Text = txtResult.Text; } if (sender.Equals(Btn0)) { if (txtResult.Text == "0") txtResult.Text =
18、 "0"; else txtResult.Text += "0"; Loadstr2.Text = txtResult.Text; } if (sender.Equals(BtnDot)) { if (txtResult.Text != "") //txtResult.Text = ""; if (txtResult.Text.C
19、ontains(".")) txtResult.Text = txtResult.Text; else txtResult.Text += "."; Loadstr2.Text = txtResult.Text; } if (sender.Equals(BtnClr)) { txtResult.Text = "";
20、Loadstr1.Text = ""; Loadstr2.Text = ""; Loadstr3.Text = ""; } if (sender.Equals(BtnPi)) { txtResult.Text = Convert.ToString(Pi); Loadstr2.Text = txtResult.Text; }
21、if (sender.Equals(BtnSquareRoot)) txtResult.Text = Convert.ToString(Math.Sqrt(Convert.ToDouble(txtResult.Text))); if (sender.Equals(BtnSquare)) txtResult.Text = Convert.ToString(Convert.ToDouble(txtResult.Text) * Convert.ToDouble(txtResult.Text));
22、 } } } //前台代码 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Calculator2._Default" %>






