Calculator  

It can be classified

Number keys

+ - * / %

= And revocation

Zeroing C The most simple

Let's take a look at the specific code of the calculator

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; namespace WindowsFormsApplication4
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
} // Record whether the operator has just been clicked
private bool isok = true;
// Records of the results
private decimal Sum;
// Record the last operator
private string PreYunsuanfu;
// Record expressions
private string Biaodashi; private void btnling_Click(object sender, EventArgs e)
{
if (isok)
{
txtshuru.Text = "";
// isok = false;
}
else
{
txtshuru.Text += "";
}
} private void btnyi_Click(object sender, EventArgs e)
{
if (isok)
{
txtshuru.Text = "";
isok = false;
}
else
{
txtshuru.Text += "";
}
} private void btner_Click(object sender, EventArgs e)
{
if (isok)
{
txtshuru.Text = "";
isok = false;
}
else
{
txtshuru.Text += "";
}
} private void btnsan_Click(object sender, EventArgs e)
{
if (isok)
{
txtshuru.Text = "";
isok = false;
}
else
{
txtshuru.Text += "";
}
} private void btnsi_Click(object sender, EventArgs e)
{
if (isok)
{
txtshuru.Text = "";
isok = false;
}
else
{
txtshuru.Text += "";
}
} private void btnwu_Click(object sender, EventArgs e)
{
if (isok)
{
txtshuru.Text = "";
isok = false;
}
else
{
txtshuru.Text += "";
}
} private void btnliu_Click(object sender, EventArgs e)
{
if (isok)
{
txtshuru.Text = "";
isok = false;
}
else
{
txtshuru.Text += "";
}
} private void btnqi_Click(object sender, EventArgs e)
{
if (isok)
{
txtshuru.Text = "";
isok = false;
}
else
{
txtshuru.Text += "";
}
} private void btnba_Click(object sender, EventArgs e)
{
if (isok)
{
txtshuru.Text = "";
isok = false;
}
else
{
txtshuru.Text += "";
}
} private void btnjiu_Click(object sender, EventArgs e)
{
if (isok)
{
txtshuru.Text = "";
isok = false;
}
else
{
txtshuru.Text += "";
}
} 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();
} private void btnClear_Click(object sender, EventArgs e)
{
txtshuru.Text = "";
txtjisuanshi.Text = "";
isok = true;
PreYunsuanfu = null;
Sum = ;
Biaodashi = "";
} private void btnchexiao_Click(object sender, EventArgs e)
{
if (!isok)
{
if (txtshuru.Text.Length == )
{
txtshuru.Text = "";
isok = true;
}
else
{
txtshuru.Text = txtshuru.Text.Substring(, txtshuru.Text.Length - );
}
}
} private void btndian_Click(object sender, EventArgs e)
{
if (txtshuru.Text == "")
{
txtshuru.Text = "0.";
}
if (!isok && !txtshuru.Text.Contains("."))
{
txtshuru.Text += ".";
}
isok = false;
} 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 = ;
PreYunsuanfu = null;
} private void btnzhengfu_Click(object sender, EventArgs e)
{
if (!isok)
{
if (decimal.Parse(txtshuru.Text) > )
{
txtshuru.Text = "-" + txtshuru.Text;
}
else
{
txtshuru.Text = txtshuru.Text.Substring();
}
}
} }
}

Calculator Very detailed

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; namespace FirstForm
{
public partial class JiSuanQi : Form
{
public JiSuanQi()
{
InitializeComponent();
} private double sum=;
private string biaodashi;
private string Preyunsuanfu;// Store the previous operator
private bool isok = true;// Used to determine whether the operator has just been clicked 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 += 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);
}
if (Preyunsuanfu == "%")
{
sum %= double.Parse(txtshuru.Text);
} biaodashi = biaodashi+ Preyunsuanfu + txtshuru.Text;
txtshuru.Text = sum.ToString();
}
}
txtjisuanshi.Text = biaodashi + yunsuanfu;
Preyunsuanfu = yunsuanfu;
isok = true; } private void btndeng_Click(object sender, EventArgs e)
{ } private void btnchexiao_Click(object sender, EventArgs e)
{ }
}
}

Calculator Another way

WindowsForm More about calculators

  1. C# in WindowsForm The use of common controls

    C# in WindowsForm The use of common controls -- 1.button( Cao Cao , Pay tribute to the emperor to make no minister ): attribute ;text: We often see a button named “ Log in ”, Edit it in its properties panel text that will do : Here's the picture :      ...

  2. 1.C#WinForm Making simple calculators on the basis

    utilize c# Language writing simple calculator : Core knowledge points : MessageBox.Show(Convert.ToString(comboBox1.SelectedIndex));// Drop down the serial number MessageBox.S ...

  3. Write your own calculator v1.1

    This change mainly uses factory mode instead of simple factory mode , The advantage of this is that if we want to expand other operations in the future , You don't have to modify the factory class all the time , It's possible to take the factory model , It is mainly to separate the logic judgment of the original simple factory class , Use it as an excuse , And ...

  4. Write your own calculator v1.0

    Today's fantasy , I want to see a few design patterns , It's better to write something to practice them . I found that this kind of calculator is more suitable , With the learning of design patterns , Will continue to improve the calculator . Including the increase of function and the improvement of algorithm . Beginners make mistakes , I hope you will not hesitate to point out ...

  5. 【IOS Development Notes 03- View related 】 Simple calculator implementation

    UIView After a few days of rapid learning , We have a preliminary understanding of IOS Some knowledge of development , In the middle because the pull is too fast , Many basic knowledge points are ignored , It's too boring to learn these knowledge points alone , We will gradually make up for it in future projects , Today we are going to study APP View ...

  6. [LeetCode] Basic Calculator Basic calculator

    Implement a basic calculator to evaluate a simple expression string. The expression string may conta ...

  7. JS- Homemade speed up gadgets : When developing a page, you need a quick calculator to calculate the width and height in proportion

    <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <meta name= ...

  8. from ArcMap Attribute field auto increment leads out the field calculator to use Python The technique of

    1. Preface       A few days ago, someone asked me ArcMap There are some ways to make the value of a field self incrementing in ? I first thought of things like SQL Server For numeric fields, auto increment can be set . So I turn on ArcCatalog View found only default values ...

  9. Front end learning PHP The sixth in the object-oriented series —— Implementation of simple graphic area calculator

    In front of the word This paper uses object-oriented technology to realize a simple graphic area calculator Graphic class //rect.class.php <?php abstract class Shape{ public $name; abs ...

Random recommendation

  1. python group()

    In regular expressions ,group() The string used to propose packet interception ,() Used to group #!/usr/bin/python import re line = "Cats are smarter than dog ...

  2. ( Integrated circuit card )ID card

    IC card (intergrated Circuit Card, Integrated circuit card ), Also known as smart cards , Smart card , Microcircuit card , Microchip cards wait . It's a microelectronic chip embedded in a device that conforms to ISO 7816 In the standard kaki , Make it into a card shape . IC ...

  3. android Common problems in development

    Android studio Use Aurora push , Display get sdk Version failed stay build.gradle(Module.app) add to android {    sourceSets.main {      ...

  4. iOS Develop learning records 【 Arrangement 】

    ◆ The development environment is based on MacBook / Mac OS 10.10 / Xcode 6.1 / iOS 8 1. About @property stay .h It's stated in @property after , Default .m No need to write @sy ...

  5. pure CSS nothing hacks Multi column layout of cross browser

    Pure utilization CSS It's not easy to create a layout with multiple columns of equal height , This tutorial will focus on the analysis of multiple problems in multi column layout , And then for you to come to a simple all tour take all solution , No pictures , Script ,CSS hacks And in the strictest XHTML Specification ...

  6. Java IO Node flow FileInput/OutputStream

    Java IO Node flow FileInput/OutputStream @author ixenos Node flow File stream File reading and writing are the most common I/O operation , Connect disk files through file stream , Read and write the contents of the file 1. The file to read ...

  7. [HAOI2011]Problem c

    Title Description to n Personal seating , Give everyone one first 1~n The number of , Set the first i The number of the individual is ai( Different people can have the same number ), Then start with the first person , Take your seats in turn , The first i Come by yourself After that, try to sit to ai, If ai Occupied , Just try ai+ ...

  8. [codeforces 901E] Cyclic Cipher Circular convolution -Bluestein&#39;s Algorithm

    The main idea of the topic : Portal Give two sequences ${B_i}.{C_i}$, The length is $n$, And ${B_i}$ Cyclic shift is linearly independent , That is, there is no set of coefficients ${X_i}$ Such that for all $k$ Both $\sum_{i=0}^{n-1} X ...

  9. 【easy】104. Maximum Depth of Binary Tree Find the maximum depth of a binary tree

    Find the maximum depth of a binary tree /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; ...

  10. Explain profound theories in simple language Java Probe technology 2---java Bytecode generation framework ASM、Javassist and byte buddy Use

    at present Java Bytecode generation framework is roughly ASM.Javassist and byte buddy Three ASM Introduction and use of the framework 1.ASM Introduce ASM It's a kind of Java Bytecode control framework , It can modify existing classes or generate classes in binary form , ...