using System; using System.Windows.Forms; using System.ComponentModel; using System.Drawing; class Calculator:Form { const int BUTTON_VERTICALSPACING=5; const int BUTTON_HORIZONTALSPACING=3; const int MEMORY_BUTTON_WIDTH=35; const int MEMORY_BUTTON_HEIGHT=35; const int MEMORY_BUTTONY=70; const int MEMORY_BUTTONX=5; const int DIGIT_BUTTON_WIDTH=35; const int DIGIT_BUTTON_HEIGHT=35; const int DIGIT_BUTTONY=MEMORY_BUTTONY; const int DIGIT_BUTTONX=MEMORY_BUTTONX+MEMORY_BUTTON_WIDTH+BUTTON_HORIZONTALSPACING+5; const int DISPLAY_HEIGHT=25; const int OTHER_BUTTON_HEIGHT=DIGIT_BUTTON_HEIGHT-10; const int OTHER_BUTTON_WIDTH=60; const int OTHER_BUTTONY=5+DISPLAY_HEIGHT+10; const int OTHER_BUTTONX=DIGIT_BUTTONX; const int FORM_HEIGHT=260; const int FORM_WIDTH=250; Button[] btnDigitOperator=new Button[20]; Button[] btnMemory=new Button[4]; Button[] btnOther=new Button[3]; Label lblDisplay; Label lblMemory; string[,] DigitCaption=new String[5,4]{{"7","4","1","0"},{"8","5","2","+/-"},{"9","6","3","."},{"/","*","-","+"},{"sqrt","%","1/x","="}}; string[] MemoryCaption={"MC","MR","MS","M+"}; string[] OtherCaption={"BackSpace","CE","C"}; static double BufferValue=0.0; static double Operand1=0.0; static double Operand2=0.0; static string Operator=""; //if true then the number does not have integral part. static bool IsFraction=false; //if digit pressed just after operator then clear display and //display only the clicked digit otherwise do concatenation static bool IsOperatorClicked=false; public Calculator() { lblDisplay=new Label(); lblDisplay.Text="0."; lblDisplay.BackColor=Color.White; lblDisplay.Location=new Point(5,5); lblDisplay.Size=new Size(FORM_WIDTH-20,DISPLAY_HEIGHT); lblDisplay.BorderStyle=System.Windows.Forms.BorderStyle.Fixed3D; lblDisplay.TextAlign=ContentAlignment.MiddleRight; this.Controls.Add(lblDisplay); lblMemory=new Label(); lblMemory.Text=""; lblMemory.BackColor=this.BackColor; lblMemory.Location=new Point(MEMORY_BUTTONX,OTHER_BUTTONY); lblMemory.Size=new Size(MEMORY_BUTTON_WIDTH,OTHER_BUTTON_HEIGHT); lblMemory.BorderStyle=System.Windows.Forms.BorderStyle.Fixed3D; lblMemory.TextAlign=ContentAlignment.MiddleCenter; this.Controls.Add(lblMemory); // Adding Memory Buttons for(int i=0;i2) { if(lblDisplay.Text.Substring(lblDisplay.Text.Length-1)==".") { lblDisplay.Text=lblDisplay.Text.Substring(0,lblDisplay.Text.Length-2) + "."; } else { lblDisplay.Text=lblDisplay.Text.Substring(0,lblDisplay.Text.Length-1); } } else { IsFraction=false; lblDisplay.Text="0."; } break; } } public static void Main() { Application.Run(new Calculator()); } }