计算器(重装)简易型

Code:
  1. using System;   
  2. using System.Collections.Generic;   
  3. using System.ComponentModel;   
  4. using System.Data;   
  5. using System.Drawing;   
  6. using System.Linq;   
  7. using System.Text;   
  8. using System.Windows.Forms;   
  9.   
  10. namespace _0125   
  11. {   
  12.     public partial class Form1 : Form   
  13.     {   
  14.         public Form1()   
  15.         {   
  16.             InitializeComponent();   
  17.         }   
  18.   
  19.         public string shu1 = string.Empty;   
  20.         public string shu2 = string.Empty;   
  21.         public string fh = string.Empty;   
  22.         public double jieguo = 0;   
  23.         private void button1_Click(object sender, EventArgs e)   
  24.         {   
  25.             if (this.textBox1.Text.Equals("0"))   
  26.             {   
  27.                 this.textBox1.Text = string.Empty;   
  28.                 this.textBox1.Text = this.textBox1.Text + "1";   
  29.             }   
  30.             else  
  31.             {    
  32.                 this.textBox1.Text = this.textBox1.Text + "1";   
  33.                 
  34.             }    
  35.         }   
  36.   
  37.         private void button2_Click(object sender, EventArgs e)   
  38.         {   
  39.             if (this.textBox1.Text.Equals("0"))   
  40.             {   
  41.                 this.textBox1.Text = string.Empty;   
  42.                 this.textBox1.Text = this.textBox1.Text + "2";   
  43.             }   
  44.   
  45.             else  
  46.             {   
  47.                 this.textBox1.Text = this.textBox1.Text + "2";   
  48.             }    
  49.         }   
  50.         private void button3_Click(object sender, EventArgs e)   
  51.         {   
  52.             if (this.textBox1.Text.Equals("0"))   
  53.             {   
  54.                 this.textBox1.Text = string.Empty;   
  55.                 this.textBox1.Text = this.textBox1.Text + "3";   
  56.             }   
  57.             else  
  58.             {   
  59.                 this.textBox1.Text = this.textBox1.Text + "3";   
  60.             }    
  61.         }   
  62.   
  63.         private void button4_Click(object sender, EventArgs e)   
  64.         {   
  65.             if (this.textBox1.Text.Equals("0"))   
  66.             {   
  67.                 this.textBox1.Text = string.Empty;   
  68.                 this.textBox1.Text = this.textBox1.Text + "4";   
  69.   
  70.             }   
  71.             else  
  72.             {   
  73.                 this.textBox1.Text = this.textBox1.Text + "4";   
  74.             }    
  75.         }   
  76.   
  77.         private void button5_Click(object sender, EventArgs e)   
  78.         {   
  79.             if (this.textBox1.Text.Equals("0"))   
  80.             {   
  81.                 this.textBox1.Text = string.Empty;   
  82.                 this.textBox1.Text = this.textBox1.Text + "5";   
  83.             }   
  84.             else  
  85.             {   
  86.                 this.textBox1.Text = this.textBox1.Text + "5";   
  87.             }   
  88.         }   
  89.   
  90.         private void button6_Click(object sender, EventArgs e)   
  91.         {   
  92.             if (this.textBox1.Text.Equals("0"))   
  93.             {   
  94.                 this.textBox1.Text = string.Empty;   
  95.                 this.textBox1.Text = this.textBox1.Text + "6";   
  96.   
  97.             }   
  98.             else  
  99.             {    
  100.                 this.textBox1.Text = this.textBox1.Text + "6";   
  101.             }    
  102.         }   
  103.   
  104.         private void button7_Click(object sender, EventArgs e)   
  105.         {   
  106.             if (this.textBox1.Text.Equals("0"))   
  107.             {   
  108.                 this.textBox1.Text = string.Empty;   
  109.                 this.textBox1.Text = this.textBox1.Text + "7";   
  110.             }   
  111.             else  
  112.             {   
  113.                 this.textBox1.Text = this.textBox1.Text + "7";   
  114.             }    
  115.         }   
  116.   
  117.         private void button8_Click(object sender, EventArgs e)   
  118.         {   
  119.             if (this.textBox1.Text.Equals("0"))   
  120.             {   
  121.                 this.textBox1.Text = string.Empty;                
  122.                 this.textBox1.Text = this.textBox1.Text + "8";   
  123.             }   
  124.             else  
  125.             {   
  126.                 this.textBox1.Text = this.textBox1.Text + "8";   
  127.             }    
  128.   
  129.         }   
  130.   
  131.         private void button9_Click(object sender, EventArgs e)   
  132.         {   
  133.             if (this.textBox1.Text.Equals("0"))   
  134.             {   
  135.                 this.textBox1.Text = string.Empty;   
  136.                 this.textBox1.Text = this.textBox1.Text + "9";   
  137.             }   
  138.             else  
  139.             {    
  140.                 this.textBox1.Text = this.textBox1.Text + "9";   
  141.             }    
  142.         }   
  143.   
  144.         private void button10_Click(object sender, EventArgs e)   
  145.         {   
  146.             if (this.textBox1.Text.Equals("0"))   
  147.             {   
  148.                 this.textBox1.Text = string.Empty;   
  149.                 this.textBox1.Text = this.textBox1.Text + "0";   
  150.             }   
  151.             else  
  152.             {     
  153.                 this.textBox1.Text = this.textBox1.Text + "0";   
  154.             }    
  155.         }   
  156.   
  157.         private void button11_Click(object sender, EventArgs e)   
  158.         {   
  159.             if (this.textBox1.Text.Equals("0"))   
  160.             {   
  161.                 this.textBox1.Text =this.textBox1.Text;    
  162.             }   
  163.             else  
  164.             {   
  165.                    
  166.                 if (this.textBox1.Text.Substring(0,1).Equals("-"))   
  167.                 {   
  168.                     this.textBox1.Text = this.textBox1.Text.Substring(1,this.textBox1.Text.Length-1);   
  169.                 }   
  170.                 else  
  171.                 {   
  172.                     this.textBox1.Text = "-" + this.textBox1.Text;   
  173.                 }   
  174.             }   
  175.         }   
  176.   
  177.         private void button12_Click(object sender, EventArgs e)   
  178.         {   
  179.             if (this.textBox1.Text.Equals("0"))   
  180.             {   
  181.                 this.textBox1.Text = this.textBox1.Text + ".";   
  182.             }   
  183.             else  
  184.             {   
  185.                 this.textBox1.Text = this.textBox1.Text + ".";   
  186.             }   
  187.         }   
  188.   
  189.         private void button16_Click(object sender, EventArgs e)   
  190.         {   
  191.             shu1 = this.textBox1.Text;   
  192.             fh = "/";   
  193.             this.textBox1.Text = "0";   
  194.   
  195.         }   
  196.   
  197.         private void button15_Click(object sender, EventArgs e)   
  198.         {   
  199.             shu1 = this.textBox1.Text;   
  200.             fh = "*";   
  201.             this.textBox1.Text = "0";   
  202.         }   
  203.   
  204.         private void button14_Click(object sender, EventArgs e)   
  205.         {   
  206.             shu1 = this.textBox1.Text;   
  207.             fh = "-";   
  208.             this.textBox1.Text = "0";   
  209.         }   
  210.   
  211.         private void button13_Click(object sender, EventArgs e)   
  212.         {   
  213.             shu1 = this.textBox1.Text;   
  214.             fh = "+";//符号赋值   
  215.             this.textBox1.Text = "0";//清空   
  216.         }   
  217.   
  218.         private void button20_Click(object sender, EventArgs e)   
  219.         {   
  220.             shu2 = this.textBox1.Text;   
  221.             if (fh.Equals("+"))   
  222.             {   
  223.                 jieguo = Convert.ToDouble(shu1) + Convert.ToDouble(shu2);   
  224.                 this.textBox1.Text = jieguo.ToString();   
  225.             }   
  226.             if (fh.Equals("-"))   
  227.             {   
  228.                 jieguo = Convert.ToDouble(shu1) - Convert.ToDouble(shu2);   
  229.                 this.textBox1.Text = jieguo.ToString();   
  230.             }   
  231.             if (fh.Equals("*"))   
  232.             {   
  233.                 jieguo = Convert.ToDouble(shu1) * Convert.ToDouble(shu2);   
  234.                 this.textBox1.Text = jieguo.ToString();   
  235.             }   
  236.             if (fh.Equals("/"))   
  237.             {   
  238.                 jieguo = Convert.ToDouble(shu1) / Convert.ToDouble(shu2);   
  239.                 this.textBox1.Text = jieguo.ToString();   
  240.             }   
  241.         }   
  242.   
  243.         private void button17_Click(object sender, EventArgs e)   
  244.         {   
  245.             this.textBox1.Text = "0";   
  246.   
  247.         }   
  248.   
  249.         private void Form1_Load(object sender, EventArgs e)   
  250.         {   
  251.           
  252.         }   
  253.     }   
  254. }   

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值