WinForm Calculator Two-step walk

Source: Internet
Author: User

namespace windowsformsapplication4{public partial class Form2:form {public Form2 () {in        Itializecomponent ();        }//Record whether the operator has just been ordered private bool isOK = true;        Record result private decimal Sum;        Records the last operator of the private string Preyunsuanfu;        Record expression private string Biaodashi; private void Form2_load (object sender, EventArgs e) {} private void Btnling_click (object sender, Eve Ntargs e) {if (isOK) {Txtshuru.               Text = "0";            isOK = false; } else {Txtshuru.            Text + = "0";                }} private void Btnyi_click (object sender, EventArgs e) {if (isOK) { Txtshuru.                Text = "1";            isOK = false; } else {Txtshuru.            Text + = "1"; }} private void Btner_click(object sender, EventArgs e) {if (isOK) {Txtshuru.                Text = "2";            isOK = false; } else {Txtshuru.            Text + = "2";                }} private void Btnsan_click (object sender, EventArgs e) {if (isOK) { Txtshuru.                Text = "3";            isOK = false; } else {Txtshuru.            Text + = "3";                }} private void Btnsi_click (object sender, EventArgs e) {if (isOK) { Txtshuru.                Text = "4";            isOK = false; } else {Txtshuru.            Text + = "4";                }} private void Btnwu_click (object sender, EventArgs e) {if (isOK) { Txtshuru.                Text = "5";            isOK = false;             } else {   Txtshuru.            Text + = "5";                }} private void Btnliu_click (object sender, EventArgs e) {if (isOK) { Txtshuru.                Text = "6";            isOK = false; } else {Txtshuru.            Text + = "6";                }} private void Btnqi_click (object sender, EventArgs e) {if (isOK) { Txtshuru.                Text = "7";            isOK = false; } else {Txtshuru.            Text + = "7";                }} private void Btnba_click (object sender, EventArgs e) {if (isOK) { Txtshuru.                Text = "8";            isOK = false; } else {Txtshuru.            Text + = "8";                }} private void Btnjiu_click (object sender, EventArgs e) {if (isOK) { Txtshuru.      Text = "9";          isOK = false; } else {Txtshuru.            Text + = "9";            }} private void Btnjia_click (object sender, EventArgs e) {if (Preyunsuanfu = = null) {Sum = decimal. Parse (Txtshuru.                Text); Biaodashi = Txtshuru.            Text;                    } else {if (!isok) {if (Preyunsuanfu = = "+") {sum = sum + decimal. Parse (Txtshuru.                    Text); } if (Preyunsuanfu = = "-") {Sum = Sum-decimal. Parse (Txtshuru.                    Text); } if (Preyunsuanfu = = "*") {sum = sum * decimal. Parse (Txtshuru.                    Text); } if (Preyunsuanfu = = "/") {Sum = Sum/decimal. Parse (Txtshuru. TEXT); } if (Preyunsuanfu = = "%") {sum = sum% decimal. Parse (Txtshuru.                    Text); } Biaodashi = Biaodashi + Preyunsuanfu + Txtshuru.                Text; }} Txtjisuanshi.            Text = Biaodashi + "+";            Preyunsuanfu = "+";            isOK = true; Txtshuru.        Text = Sum.tostring ();                 private void Btnjian_click (object sender, EventArgs e) {if (Preyunsuanfu = = null) { Sum = Decimal. Parse (Txtshuru.                Text); Biaodashi = Txtshuru.            Text;                    } else {if (!isok) {if (Preyunsuanfu = = "+") {sum = sum + decimal. Parse (Txtshuru.                    Text); } if (Preyunsuanfu = = "-") {Sum = Sum-decimal. Parse (Txtshuru.                    Text); } if (Preyunsuanfu = = "*") {sum = sum * decimal. Parse (Txtshuru.                    Text); } if (Preyunsuanfu = = "/") {Sum = Sum/decimal. Parse (Txtshuru.                    Text); } if (Preyunsuanfu = = "%") {sum = sum% decimal. Parse (Txtshuru.                    Text); } Biaodashi = Biaodashi + Preyunsuanfu + Txtshuru.                Text; }} Txtjisuanshi.            Text = Biaodashi + "-";            Preyunsuanfu = "-";            isOK = true; Txtshuru.        Text = Sum.tostring ();            private void Btncheng_click (object sender, EventArgs e) {if (Preyunsuanfu = = null) {Sum = decimal. Parse (Txtshuru.                Text); Biaodashi = Txtshuru.            Text;         } else   {if (!isok) {if (Preyunsuanfu = = "+") { sum = sum + decimal. Parse (Txtshuru.                    Text); } if (Preyunsuanfu = = "-") {Sum = Sum-decimal. Parse (Txtshuru.                    Text); } if (Preyunsuanfu = = "*") {sum = sum * decimal. Parse (Txtshuru.                    Text); } if (Preyunsuanfu = = "/") {Sum = Sum/decimal. Parse (Txtshuru.                    Text); } if (Preyunsuanfu = = "%") {sum = sum% decimal. Parse (Txtshuru.                    Text); } Biaodashi = Biaodashi + Preyunsuanfu + Txtshuru.                Text; }} Txtjisuanshi.            Text = Biaodashi + "*";            Preyunsuanfu = "*"; isOK = true; Txtshuru.        Text = Sum.tostring ();                private void Btnchu_click (object sender, EventArgs e) {if (Preyunsuanfu = = null) { Sum = Decimal. Parse (Txtshuru.                Text); Biaodashi = Txtshuru.            Text;                    } else {if (!isok) {if (Preyunsuanfu = = "+") {sum = sum + decimal. Parse (Txtshuru.                    Text); } if (Preyunsuanfu = = "-") {Sum = Sum-decimal. Parse (Txtshuru.                    Text); } if (Preyunsuanfu = = "*") {sum = sum * decimal. Parse (Txtshuru.                    Text); } if (Preyunsuanfu = = "/") {Sum = Sum/decimal. Parse (Txtshuru.                    Text); } if (Preyunsuanfu == "%") {sum = sum% decimal. Parse (Txtshuru.                    Text); } Biaodashi = Biaodashi + Preyunsuanfu + Txtshuru.                Text; }} Txtjisuanshi.            Text = Biaodashi + "/";            Preyunsuanfu = "/";            isOK = true; Txtshuru.        Text = Sum.tostring ();                private void Btnmo_click (object sender, EventArgs e) {if (Preyunsuanfu = = null) { Sum = Decimal. Parse (Txtshuru.                Text); Biaodashi = Txtshuru.            Text;                    } else {if (!isok) {if (Preyunsuanfu = = "+") {sum = sum + decimal. Parse (Txtshuru.                    Text); } if (Preyunsuanfu = = "-") {Sum = Sum-decimal. Parse (Txtshuru.                    Text); } if (PreyunSuanfu = = "*") {sum = sum * decimal. Parse (Txtshuru.                    Text); } if (Preyunsuanfu = = "/") {Sum = Sum/decimal. Parse (Txtshuru.                    Text); } if (Preyunsuanfu = = "%") {sum = sum% decimal. Parse (Txtshuru.                    Text); } Biaodashi = Biaodashi + Preyunsuanfu + Txtshuru.                Text; }} Txtjisuanshi.            Text = Biaodashi + "%";            Preyunsuanfu = "%";            isOK = true; Txtshuru.        Text = Sum.tostring (); The private void Btnclear_click (object sender, EventArgs e) {Txtshuru.            Text = "0"; Txtjisuanshi.            Text = "";            isOK = true;            Preyunsuanfu = null;            Sum = 0;        Biaodashi = "";   private void Btnchexiao_click (object sender, EventArgs e)     {if (!isok) {if (Txtshuru. Text.length = = 1) {Txtshuru.                    Text = "0";                isOK = true; } else {Txtshuru. Text = Txtshuru. Text.substring (0, Txtshuru.                TEXT.LENGTH-1); }}} private void Btndian_click (object sender, EventArgs e) {if (Txtshuru. Text = = "0") {Txtshuru.            Text = "0."; } if (!isok &&!txtshuru.            Text.contains (".")) {Txtshuru.            Text + = ".";        } isOK = false; The private void Btndeng_click (object sender, EventArgs e) {Txtjisuanshi.            Text = ""; if (Preyunsuanfu = = "+") {sum = sum + decimal. Parse (Txtshuru.            Text); } if (Preyunsuanfu = = "-") {Sum = Sum-decimal.Parse (Txtshuru.            Text); } if (Preyunsuanfu = = "*") {sum = sum * decimal. Parse (Txtshuru.            Text); } if (Preyunsuanfu = = "/") {Sum = Sum/decimal. Parse (Txtshuru.            Text); } if (Preyunsuanfu = = "%") {sum = sum% decimal. Parse (Txtshuru.            Text); } Txtshuru.            Text = Sum.tostring ();            isOK = true;            Biaodashi = "";            Sum = 0;        Preyunsuanfu = null;                private void Btnzhengfu_click (object sender, EventArgs e) {if (!isok) { if (decimal. Parse (Txtshuru. Text) > 0) {Txtshuru. Text = "-" + Txtshuru.                Text; } else {Txtshuru. Text = Txtshuru.                Text.substring (1); }            }        }    }}

  

The button event

namespace firstform{public partial class Jisuanqi:form {public Jisuanqi () {Initializec        Omponent (); The private double sum=0;//records the result of the previous step, the private string biaodashi;//the formula before the click operator private String Preyunsuanfu        ///the operator before storing private bool isOK = true;//used to determine whether the operator has just been ordered private void Btnling_click (object sender, EventArgs e)            {button btn = (button) sender; if (isOK) {Txtshuru. Text = btn.                Text;            isOK = false; } else {Txtshuru. Text + = btn.            Text;            }} private void Btnjia_click (object sender, EventArgs e) {button btn = (button) sender; String Yunsuanfu = btn.            Text; if (Preyunsuanfu = = null) {Biaodashi + = Txtshuru.                Text; sum = Double. Parse (Txtshuru.            Text); } else {if (!iSok) {if (Preyunsuanfu = = "+") {sum + = Doubl E.parse (Txtshuru.                    Text); } if (Preyunsuanfu = = "-") {sum-= double. Parse (Txtshuru.                    Text); } if (Preyunsuanfu = = "*") {sum *= double. Parse (Txtshuru.                    Text); } if (Preyunsuanfu = = "/") {sum/= double. Parse (Txtshuru.                    Text); } if (Preyunsuanfu = = "%") {sum%= double. Parse (Txtshuru.                    Text); } Biaodashi = biaodashi+ Preyunsuanfu + Txtshuru.                    Text; Txtshuru. Text = Sum.                ToString (); }} Txtjisuanshi.            Text = Biaodashi + Yunsuanfu;         Preyunsuanfu = Yunsuanfu;   isOK = true; }      }}

  

WinForm Calculator Two-step walk

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.