收藏 分销(赏)

.net-计算器

上传人:仙人****88 文档编号:11959332 上传时间:2025-08-22 格式:DOCX 页数:8 大小:26.44KB 下载积分:10 金币
下载 相关 举报
.net-计算器_第1页
第1页 / 共8页
.net-计算器_第2页
第2页 / 共8页


点击查看更多>>
资源描述
功能看界面就是了, //后台代码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_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 len; // Char[] c = { '+', '-', '*', '/' }; if (sender.Equals(BtnEqual)) { str1 = Loadstr1.Text; len = str1.Length; str2 =Loadstr2.Text; str3 = Loadstr3.Text; // char[] strArry = str1.ToCharArray(); num1 =Convert.ToDouble(str3); num2 = Convert.ToDouble(txtResult .Text); if (txtResult.Text == "") { txtResult.Text = " "; } // num2=con 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); break; case "/": if (num2 == 0) txtResult.Text = "除数不能为0"; else txtResult.Text = Convert.ToString(num1 / num2); break; } //num2 = result; // txtResult.Text = Convert.ToString(num2); } if (sender.Equals(BtnAdd)) { Loadstr1.Text ="+"; Loadstr3.Text = txtResult.Text; txtResult.Text = ""; } if (sender.Equals(BtnSub)) { Loadstr1.Text ="-"; Loadstr3.Text = txtResult.Text; txtResult.Text = ""; } if (sender.Equals(BtnMul)) { Loadstr1.Text = "*"; Loadstr3.Text = txtResult.Text; txtResult.Text = ""; } if (sender.Equals(BtnDivide)) { Loadstr1.Text = "/"; Loadstr3.Text = txtResult.Text; txtResult.Text = ""; } if (sender.Equals(Btn1)) { if (txtResult.Text == "0") txtResult.Text = "1"; else txtResult.Text += "1"; Loadstr2.Text = txtResult.Text; } if (sender.Equals(Btn2)) { if (txtResult.Text == "0") txtResult.Text = "2"; else txtResult.Text += "2"; Loadstr2.Text = txtResult.Text; } if (sender.Equals(Btn3)) { if (txtResult.Text == "0") txtResult.Text = "3"; else txtResult.Text += "3"; Loadstr2.Text = txtResult.Text; } if (sender.Equals(Btn4)) { if (txtResult.Text == "0") txtResult.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"; Loadstr2.Text = txtResult.Text; } if (sender.Equals(Btn6)) { if (txtResult.Text == "0") txtResult.Text = "6"; else txtResult.Text += "6"; Loadstr2.Text = txtResult.Text; } if (sender.Equals(Btn7)) { if (txtResult.Text == "0") txtResult.Text = "7"; else txtResult.Text += "7"; Loadstr2.Text = txtResult.Text; } if (sender.Equals(Btn8)) { if (txtResult.Text == "0") txtResult.Text = "8"; else txtResult.Text += "8"; Loadstr2.Text = txtResult.Text; } if (sender.Equals(Btn9)) { if (txtResult.Text == "0") txtResult.Text = "9"; else txtResult.Text += "9"; Loadstr2.Text = txtResult.Text; } if (sender.Equals(Btn0)) { if (txtResult.Text == "0") txtResult.Text = "0"; else txtResult.Text += "0"; Loadstr2.Text = txtResult.Text; } if (sender.Equals(BtnDot)) { if (txtResult.Text != "") //txtResult.Text = ""; if (txtResult.Text.Contains(".")) txtResult.Text = txtResult.Text; else txtResult.Text += "."; Loadstr2.Text = txtResult.Text; } if (sender.Equals(BtnClr)) { txtResult.Text = ""; Loadstr1.Text = ""; Loadstr2.Text = ""; Loadstr3.Text = ""; } if (sender.Equals(BtnPi)) { txtResult.Text = Convert.ToString(Pi); Loadstr2.Text = txtResult.Text; } 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)); } } } //前台代码 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Calculator2._Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>迷你计算器</title> <style type="text/css"> #container { border-bottom: solid 1px #5c9cc0; border-top: solid 1px #5c9cc0; border-left: solid 1px #5c9cc0; border-right: solid 1px #5c9cc0; font-size: 14px; width: 400px; height: 300px; text-align: center; background-color: #eef3f7; margin: 0px auto; } .Button { border-right: #7b9ebd 1px solid; padding-right: 2px; border-top: #7b9ebd 1px solid; padding-left: 2px; filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#ffffff, EndColorStr=#cecfde); border-left: #7b9ebd 1px solid; cursor: hand; color: black; padding-top: 2px; border-bottom: #7b9ebd 1px solid; width: 50px; height: 30px; font-size: 14px; } .TextBox { width: 310px; height: 30px; text-align: right; vertical-align: bottom; font-size: 20px; } #title { font-family: 黑体; font-size: 18px; height: 18px; filter: blur(strength=2,direction=135); color: #6666ff; } </style> </head> <body> <form id="form1" runat="server"> <div id="container"> <br /> <div id="title">迷你计算器<br /></div> <asp:TextBox ID="txtResult" runat="server" CssClass="TextBox" Enabled="False" ></asp:TextBox> <br /> <br /> <br /> <asp:Button ID="Btn1" runat="server" CssClass="Button" Text="1" OnClick="Compute"/> &nbsp;<asp:Button ID="Btn2" runat="server" CssClass="Button" Text="2" OnClick="Compute"/> &nbsp;<asp:Button ID="Btn3" runat="server" CssClass="Button" Text="3" OnClick="Compute" /> &nbsp;<asp:Button ID="BtnClr" runat="server" CssClass="Button" Text="清除" OnClick="Compute"/> &nbsp;<asp:Button ID="BtnAdd" runat="server" CssClass="Button" Text="+" OnClick="Compute"/> <br /> <br /> <asp:Button ID="Btn4" runat="server" CssClass="Button" Text="4" OnClick="Compute"/> &nbsp;<asp:Button ID="Btn5" runat="server" CssClass="Button" Text="5" OnClick="Compute"/> &nbsp;<asp:Button ID="Btn6" runat="server" CssClass="Button" Text="6" OnClick="Compute"/> &nbsp;<asp:Button ID="BtnPi" runat="server" CssClass="Button" Text="Pi" OnClick="Compute"/> &nbsp;<asp:Button ID="BtnSub" runat="server" CssClass="Button" Text="-" OnClick="Compute"/> <br /> <br /> <asp:Button ID="Btn7" runat="server" CssClass="Button" Text="7" OnClick="Compute"/> &nbsp;<asp:Button ID="Btn8" runat="server" CssClass="Button" Text="8" OnClick="Compute"/> &nbsp;<asp:Button ID="Btn9" runat="server" CssClass="Button" Text="9" OnClick="Compute"/> &nbsp;<asp:Button ID="BtnSquareRoot" runat="server" CssClass="Button" Text="平方根" OnClick="Compute"/> &nbsp;<asp:Button ID="BtnMul" runat="server" CssClass="Button" Text="*" OnClick="Compute"/> <br /> <br /> <asp:Button ID="Btn0" runat="server" CssClass="Button" Text="0" OnClick="Compute"/> &nbsp;<asp:Button ID="BtnDot" runat="server" CssClass="Button" Text="." OnClick="Compute"/> &nbsp;<asp:Button ID="BtnEqual" runat="server" CssClass="Button" Text="=" OnClick="Compute"/> &nbsp;<asp:Button ID="BtnSquare" runat="server" CssClass="Button" Text="平方" OnClick="Compute"/> &nbsp;<asp:Button ID="BtnDivide" runat="server" CssClass="Button" Text="/" OnClick="Compute"/> </div> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<asp:Label ID="Loadstr3" runat="server" Visible="False"></asp:Label> &nbsp;&nbsp;&nbsp;<asp:Label ID="Loadstr1" runat="server" CssClass="Button" Visible="False">显示正在进行的运算</asp:Label> &nbsp; &nbsp;<asp:Label ID="Loadstr2" runat="server" Visible="False"></asp:Label> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </form> </body> </html>
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 包罗万象 > 大杂烩

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服