WinForm (iv)--Simple calculator production

Source: Internet
Author: User
Tags what operator

Code area:

usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespacewindowsformsapplication2{ Public Partial classForm1:form {//store Last click on what button, 0 means nothing to click, 1 for the number of clicks on the button, 2 for the operator clicked        Private intPrev =0; //intermediate results for storage calculations        Private decimalZJ =0; //record what operator was last pressed        Private stringPREVYSF ="+";  PublicForm1 () {InitializeComponent (); }        //number Key button        Private voidButton8_click (Objectsender, EventArgs e) {            //Convert an event source to a buttonButton btn = Sender asButton; //replace (if the text box below contains 0 or the last time you clicked the operator)            if(prev = =2|| Txtbottom. Text = ="0") {Txtbottom. Text=btn.            Text; }            //Append (if the contents of the text box below are not 0 and the last time there is no click operator)            Else{Txtbottom. Text+=btn.            Text; }            //Click the number buttonPrev =1; }        //operator Buttons        Private voidButton17_click (Objectsender, EventArgs e) {Button btn= Sender asButton; //last hit a number            if(prev = =1) {txttop. Text+ = Txtbottom. Text +btn.                Text; Switch(PREVYSF) { Case "+": ZJ= ZJ +Convert.todecimal (Txtbottom.                        Text);  Break;  Case "-": ZJ= ZJ-Convert.todecimal (Txtbottom.                        Text);  Break;  Case "*": ZJ= ZJ *Convert.todecimal (Txtbottom.                        Text);  Break;  Case "/": ZJ= ZJ/Convert.todecimal (Txtbottom.                        Text);  Break; } txtbottom. Text=ZJ.             ToString (); }            //the operator was last pressed            Else            {                strings =Txttop.                Text; S= S.substring (0, S.length-1); S= S +btn.                Text; Txttop. Text=s; }            //Click the operatorPrev =2; //Log the operatorPREVYSF =btn.                  Text; }        //Clear 0 Button        Private voidButton19_click (Objectsender, EventArgs e) {Txttop. Text=""; Txtbottom. Text="0"; Prev=0; ZJ=0; PREVYSF="+"; }        Private voidButton20_click (Objectsender, EventArgs e) {Txtbottom. Text="0"; }        //equal sign button        Private voidButton4_Click (Objectsender, EventArgs e) {Button btn= Sender asButton; Txttop. Text+ = Txtbottom. Text +btn.            Text; Switch(PREVYSF) { Case "+": ZJ= ZJ +Convert.todecimal (Txtbottom.                    Text);  Break;  Case "-": ZJ= ZJ-Convert.todecimal (Txtbottom.                    Text);  Break;  Case "*": ZJ= ZJ *Convert.todecimal (Txtbottom.                    Text);  Break;  Case "/": ZJ= ZJ/Convert.todecimal (Txtbottom.                    Text);  Break; } txtbottom. Text=ZJ.            ToString (); Txttop. Text=""; ZJ=0; }        //Point        Private voidButton3_Click (Objectsender, EventArgs e) {Txtbottom. Text+="."; }    }}

WinForm (iv)--Simple calculator production

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.