国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C#實現的簡單整數四則運算計算器功能示例

2020-01-24 00:27:40
字體:
來源:轉載
供稿:網友

本文實例講述了C#實現的簡單整數四則運算計算器功能。分享給大家供大家參考,具體如下:

運行效果圖如下:

具體代碼如下:

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace 計算器{  public partial class Form1 : Form  {    public Form1()    {      InitializeComponent();    }    public string num;    public int flag;//用于判斷輸入的操作符    public double num1, num2;    private void num0_button_Click(object sender, EventArgs e)    {      num = num + "0";      num2 = Convert.ToDouble(num);      textBox.Text = num;    }    private void num1_button_Click(object sender, EventArgs e)//重點算法1    {      if (textBox.Text == "0")      {        num = "1";        textBox.Text = Convert.ToString(num);      }      else      {        num = num + "1";        num2 = Convert.ToDouble(num);        textBox.Text = num;      }    }    private void num2_button_Click(object sender, EventArgs e)    {      if (textBox.Text == "0")      {        num = "2";        textBox.Text = Convert.ToString(num);      }      else      {        num = num + "2";        num2 = Convert.ToDouble(num);        textBox.Text = num;      }    }    private void num3_button_Click(object sender, EventArgs e)    {      if (textBox.Text == "0")      {        num = "3";        textBox.Text = Convert.ToString(num);      }      else      {        num = num + "3";        num2 = Convert.ToDouble(num);        textBox.Text = num;      }    }    private void num4_button_Click(object sender, EventArgs e)    {      if (textBox.Text == "0")      {        num = "4";        textBox.Text = Convert.ToString(num);      }      else      {        num = num + "4";        num2 = Convert.ToDouble(num);        textBox.Text = num;      }    }    private void num5_button_Click(object sender, EventArgs e)    {      if (textBox.Text == "0")      {        num = "5";        textBox.Text = Convert.ToString(num);      }      else      {        num = num + "5";        num2 = Convert.ToDouble(num);        textBox.Text = num;      }    }    private void num6_button_Click(object sender, EventArgs e)    {      if (textBox.Text == "0")      {        num = "6";        textBox.Text = Convert.ToString(num);      }      else      {        num = num + "6";        num2 = Convert.ToDouble(num);        textBox.Text = num;      }    }    private void num7_button_Click(object sender, EventArgs e)    {      if (textBox.Text == "0")      {        num = "7";        textBox.Text = Convert.ToString(num);      }      else      {        num = num + "7";        num2 = Convert.ToDouble(num);        textBox.Text = num;      }    }    private void num8_button_Click(object sender, EventArgs e)    {      if (textBox.Text == "0")      {        num = "8";        textBox.Text = Convert.ToString(num);      }      else      {        num = num + "8";        num2 = Convert.ToDouble(num);        textBox.Text = num;      }    }    private void num9_button_Click(object sender, EventArgs e)    {      if (textBox.Text == "0")      {        num = "9";        textBox.Text = Convert.ToString(num);      }      else      {        num = num + "9";        num2 = Convert.ToDouble(num);        textBox.Text = num;      }    }    private void add_button_Click(object sender, EventArgs e)//重點算法2    {      if (textBox.Text.Length > 0)      {        num1 = Convert.ToDouble(textBox .Text);        num = "";        flag = 1;        textBox.Text = "";        textBox.Focus();      }    }    private void dev_button_Click(object sender, EventArgs e)    {      if (textBox.Text.Length > 0)      {        num1 = Convert.ToDouble(textBox.Text);        num = "";        flag = 2;        textBox.Text = "";        textBox.Focus();      }    }    private void mul_button_Click(object sender, EventArgs e)    {      if (textBox.Text.Length > 0)      {        num1 = Convert.ToDouble(textBox.Text);        num = "";        flag = 3;        textBox.Text = "";        textBox.Focus();      }    }    private void chu_button_Click(object sender, EventArgs e)    {      if (textBox.Text.Length > 0)      {        num1 = Convert.ToDouble(textBox.Text);        num = "";        flag = 4;        // textBox.Text = "";        textBox.Focus();      }    }    private void equ_button_Click(object sender, EventArgs e)    {      switch (flag)      {        case 1:          textBox.Text = Convert.ToString(num1+Convert .ToDouble(num));//重點算法3          num2 = Convert.ToDouble(textBox .Text);          break;        case 2:          textBox.Text = Convert.ToString(num1 - Convert.ToDouble(num));          num2 = Convert.ToDouble(textBox.Text);          break;        case 3:          textBox.Text = Convert.ToString(num1 * Convert.ToDouble(num));          num2 = Convert.ToDouble(textBox.Text);          break;        case 4:          textBox.Text = Convert.ToString(num1 / Convert.ToDouble(num));          num2 = Convert.ToDouble(textBox.Text);          break;      }    }    private void re_button_Click(object sender, EventArgs e)    {      num = "";      textBox.Text = "0";    }  }}

PS:這里再為大家推薦幾款計算工具供大家進一步參考借鑒:

在線一元函數(方程)求解計算工具:
http://tools.VeVB.COm/jisuanqi/equ_jisuanqi

科學計算器在線使用_高級計算器在線計算:
http://tools.VeVB.COm/jisuanqi/jsqkexue

在線計算器_標準計算器:
http://tools.VeVB.COm/jisuanqi/jsq

更多關于C#相關內容感興趣的讀者可查看本站專題:《C#數據結構與算法教程》、《C#程序設計之線程使用技巧總結》、《C#常見控件用法教程》、《WinForm控件用法總結》、《C#數組操作技巧總結》及《C#面向對象程序設計入門教程

希望本文所述對大家C#程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 灵宝市| 宝坻区| 石城县| 永吉县| 江门市| 喀什市| 甘谷县| 白玉县| 县级市| 蕉岭县| 新和县| 共和县| 莱州市| 赤城县| 舒兰市| 淮南市| 仪征市| 乌兰浩特市| 百色市| 招远市| 永昌县| 大田县| 鹤岗市| 罗平县| 奉贤区| 得荣县| 罗源县| 湟中县| 时尚| 哈尔滨市| 本溪市| 永川市| 云南省| 崇礼县| 西乌| 阿克苏市| 凤庆县| 开原市| 新绛县| 喜德县| 新邵县|