:
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