精华内容
下载资源
问答
  • C# 编写计算器

    2013-07-14 09:23:00
    C#编写的简单计算器,能够实现加减乘除。
  • 使用C#语言编写计算器项目,包含整个项目的源代码,适合C#语言初学者使用练习,注释简单详细,亲测可用。
  • C#编写计算器源码

    2018-09-21 16:28:23
    C#编写计算器源码,直接运行,可用。
  • C#编写计算器

    2013-11-07 19:23:25
    C#计算器,用于计算加减乘除,自己做的课堂作业
  • 一设计思路 用 C#写的比较基础的 windows Form 程序 , 该计算器实现了基础的数学运算 , 如 加 , 减 , 乘 , 除等任务 . 主要是通过该程序学习 的 编程环境 , 以及 windows Form程序 . 主要针对初学者 我们分两部份来...
  • C#编写计算器,基本功能加减乘除已实现 可成功运行
  • C#编写计算器

    2018-12-07 18:44:00
    零有点问题,而且目前只能做一些简单的运算,+、-、*、/、平方、开根号 希望有大佬指正我的错误 感谢 using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;...

    零有点问题,而且目前只能做一些简单的运算,+、-、*、/、平方、开根号

    希望有大佬指正我的错误

    感谢

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;

    namespace WindowsFormsApplication2
    {
    public partial class Form1 : Form
    {
    double a;//第一个运算数
    double b;//第二个运算数
    string d;//结果
    public Form1()
    {
    InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
    textBox1.Text += "1";
    }

    private void button2_Click(object sender, EventArgs e)
    {
    textBox1.Text += "2";
    }

    private void button3_Click(object sender, EventArgs e)
    {
    textBox1.Text += "3";
    }

    private void button4_Click(object sender, EventArgs e)
    {
    textBox1.Text += "4";
    }

    private void button5_Click(object sender, EventArgs e)
    {
    textBox1.Text += "5";
    }

    private void button6_Click(object sender, EventArgs e)
    {
    textBox1.Text += "6";
    }

    private void button7_Click(object sender, EventArgs e)
    {
    textBox1.Text += "7";
    }

    private void button8_Click(object sender, EventArgs e)
    {
    textBox1.Text += "8";
    }

    private void button9_Click(object sender, EventArgs e)
    {
    textBox1.Text += "9";
    }

    private void button16_Click(object sender, EventArgs e)
    {
    textBox1.Text += "0";
    if (d == "/")
    {
    MessageBox.Show("除数不能为零", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
    }
    }

    private void button14_Click(object sender, EventArgs e)
    {
    b = double.Parse(textBox1.Text);//parse 解析,把字符串转化为整型,转换数据类型
    textBox1.Text = "";
    d = "+";
    }

    private void button15_Click(object sender, EventArgs e)
    {
    b = double.Parse(textBox1.Text);
    textBox1.Text = "";
    d = "-";
    }

    private void button12_Click(object sender, EventArgs e)
    {
    b = double.Parse(textBox1.Text);
    textBox1.Text = "";
    d = "*";
    }

    private void button13_Click(object sender, EventArgs e)
    {
    b = double.Parse(textBox1.Text);
    textBox1.Text = "";
    d = "/";
    }

    private void button10_Click(object sender, EventArgs e)
    {
    b = double.Parse(textBox1.Text);
    textBox1.Text = "";
    d = "pow";
    }

    private void button11_Click(object sender, EventArgs e)
    {
    b = double.Parse(textBox1.Text);
    textBox1.Text = "";
    d = "sqrt";
    }

    private void button18_Click(object sender, EventArgs e)
    {
    switch (d)
    {
    case "+": a=b+ double.Parse(textBox1.Text);
    break;
    case "-": a = b - double.Parse(textBox1.Text);
    break;
    case "*": a = b * double.Parse(textBox1.Text);
    break;
    case "/": a = b / double.Parse(textBox1.Text);
    break;
    case "pow": a = Math.Pow(b,2.0);
    break;
    case "sqrt": a = Math.Sqrt(b);
    break;
    }
    textBox1.Text = a + "";
    }

    private void button19_Click(object sender, EventArgs e)
    {
    textBox1.Text = "";
    }

    private void button17_Click(object sender, EventArgs e)//小数点
    {
    if (textBox1.Text != "")
    {
    textBox1.Text += ".";
    }
    }
    }
    }

    转载于:https://www.cnblogs.com/zhang-1999/p/10084499.html

    展开全文
  • 基于visual studio2019 C#编写计算器,有需要的可以看看;
  • 我使用C#编程有半年多,可以说我主要看过的书就是这一本,当然基础的东西是少不了要学习的,如果你是一个入门者,一开始就学习这本书可能感觉有些吃力,但是只要你有一些编程的经验,对于基础的东西来说还是不成问题的,...
  • C#计算器编写代码

    2020-12-31 11:54:07
    利用C#编写一个计算器。如下图,能够完成基本的四则运算。 当然这个程序甚至还不上Windows附件那个自带的多功能计算器。  不过这个程序的逻辑还是非常值得思考的,首先你要考虑好用户按+ – * / =等运算符号、...
  • C#编写的一个计算器,按过等于button后,怎么才能能解决鼠标点进文本框继续输入数字的问题。
  • 在项目下添加一个类命名为“计算器“4.添加如下图WinForm.以下是程序的实现代码:using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms...

    1.打开vs.net (2003\2005都可).

    2.建立一个Windows应用程序

    3.在项目下添加一个类命名为“计算器“

    4.添加如下图WinForm.

    以下是程序的实现代码:

    using System;

    using System.Drawing;

    using System.Collections;

    using System.ComponentModel;

    using System.Windows.Forms;

    using System.Data;

    namespace 计算器

    {

    ///

    /// Form1 的摘要说明。

    ///

    public class Form1 : System.Windows.Forms.Form

    {

    private System.Windows.Forms.Button button4;

    private System.Windows.Forms.Button button10;

    private System.Windows.Forms.Button button15;

    private System.Windows.Forms.Button button16;

    private System.Windows.Forms.Button button22;

    private System.Windows.Forms.Button ce;

    private System.Windows.Forms.Button c;

    private System.Windows.Forms.Button btn_7;

    private System.Windows.Forms.Button btn_8;

    private System.Windows.Forms.Button btn_9;

    private System.Windows.Forms.Button btn_div;

    private System.Windows.Forms.Button btn_sqr;

    private System.Windows.Forms.Button btn_4;

    private System.Windows.Forms.Button btn_5;

    private System.Windows.Forms.Button btn_6;

    private System.Windows.Forms.Button btn_mul;

    private System.Windows.Forms.Button btn_1;

    private System.Windows.Forms.Button btn_2;

    private System.Windows.Forms.Button btn_3;

    private System.Windows.Forms.Button btn_sub;

    private System.Windows.Forms.Button btn_rev;

    private System.Windows.Forms.Button btn_0;

    private System.Windows.Forms.Button btn_sign;

    private System.Windows.Forms.Button btn_dot;

    private System.Windows.Forms.Button btn_add;

    private System.Windows.Forms.Button btn_equ;

    private System.Windows.Forms.MainMenu mainMenu1;

    private System.Windows.Forms.MenuItem menuItemEdior;

    private System.Windows.Forms.MenuItem menuItemCopy;

    private System.Windows.Forms.MenuItem menuItemPaste;

    private System.Windows.Forms.TextBox txtShow;

    private System.Windows.Forms.Label lblText;

    private System.Windows.Forms.MenuItem menuItemAbout;

    private System.Windows.Forms.MenuItem menuItemHelp;

    private System.Windows.Forms.MenuItem menuItemLink;

    private System.Windows.Forms.Button buttonBack;

    ///

    /// 必需的设计器变量。

    ///

    private System.ComponentModel.Container components = null;

    public Form1()

    {

    //

    // Windows 窗体设计器支持所必需的

    //

    InitializeComponent();

    //

    // TODO: 在 InitializeComponent 调用后添加任何构造函数代码

    //

    }

    ///

    /// 清理所有正在使用的资源。

    ///

    protected override void Dispose( bool disposing )

    {

    if( disposing )

    {

    if (components != null)

    {

    components.Dispose();

    }

    }

    base.Dispose( disposing );

    }

    #region Windows 窗体设计器生成的代码

    ///

    /// 设计器支持所需的方法 - 不要使用代码编辑器修改

    /// 此方法的内容。

    ///

    private void InitializeComponent()

    {

    this.mainMenu1 = new System.Windows.Forms.MainMenu();

    this.menuItemEdior = new System.Windows.Forms.MenuItem();

    this.menuItemCopy = new System.Windows.Forms.MenuItem();

    this.menuItemPaste = new System.Windows.Forms.MenuItem();

    this.menuItemAbout = new System.Windows.Forms.MenuItem();

    this.menuItemHelp = new System.Windows.Forms.MenuItem();

    this.menuItemLink = new System.Windows.Forms.MenuItem();

    this.lblText = new System.Windows.Forms.Label();

    this.btn_add = new System.Windows.Forms.Button();

    this.btn_dot = new System.Windows.Forms.Button();

    this.btn_sign = new System.Windows.Forms.Button();

    this.btn_0 = new System.Windows.Forms.Button();

    this.button22 = new System.Windows.Forms.Button();

    this.btn_rev = new System.Windows.Forms.Button();

    this.btn_sub = new System.Windows.Forms.Button();

    this.btn_3 = new System.Windows.Forms.Button();

    this.btn_2 = new System.Windows.Forms.Button();

    this.btn_1 = new System.Windows.Forms.Button();

    this.button16 = new System.Windows.Forms.Button();

    this.button15 = new System.Windows.Forms.Button();

    this.btn_mul = new System.Windows.Forms.Button();

    this.btn_6 = new System.Windows.Forms.Button();

    this.btn_5 = new System.Windows.Forms.Button();

    this.btn_4 = new System.Windows.Forms.Button();

    this.btn_equ = new System.Windows.Forms.Button();

    this.button10 = new System.Windows.Forms.Button();

    this.btn_sqr = new System.Windows.Forms.Button();

    this.btn_div = new System.Windows.Forms.Button();

    this.btn_9 = new System.Windows.Forms.Button();

    this.btn_8 = new System.Windows.Forms.Button();

    this.btn_7 = new System.Windows.Forms.Button();

    this.txtShow = new System.Windows.Forms.TextBox();

    this.button4 = new System.Windows.Forms.Button();

    this.c = new System.Windows.Forms.Button();

    this.ce = new System.Windows.Forms.Button();

    this.buttonBack = new System.Windows.Forms.Button();

    this.SuspendLayout();

    //

    // mainMenu1

    //

    this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {

    this.menuItemEdior,

    this.menuItemAbout});

    //

    // menuItemEdior

    //

    this.menuItemEdior.Index = 0;

    this.menuItemEdior.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {

    this.menuItemCopy,

    this.menuItemPaste});

    this.menuItemEdior.Text = "编辑(&E)";

    //

    // menuItemCopy

    //

    this.menuItemCopy.Index = 0;

    this.menuItemCopy.Text = "复制(&C)";

    this.menuItemCopy.Click += new System.EventHandler(this.menuItem3_Click);

    //

    // menuItemPaste

    //

    this.menuItemPaste.Index = 1;

    this.menuItemPaste.Text = "粘贴(&P)";

    //

    // menuItemAbout

    //

    this.menuItemAbout.Index = 1;

    this.menuItemAbout.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {

    this.menuItemHelp,

    this.menuItemLink});

    this.menuItemAbout.Text = "关于(&A)";

    //

    // menuItemHelp

    //

    this.menuItemHelp.Index = 0;

    this.menuItemHelp.Text = "帮助(&H)";

    this.menuItemHelp.Click += new System.EventHandler(this.menuItemHelp_Click);

    //

    // menuItemLink

    //

    this.menuItemLink.Index = 1;

    this.menuItemLink.Text = "关于(&L)";

    this.menuItemLink.Click += new System.EventHandler(this.menuItemLink_Click);

    //

    // lblText

    //

    this.lblText.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;

    this.lblText.Location = new System.Drawing.Point(16, 43);

    this.lblText.Name = "lblText";

    this.lblText.Size = new System.Drawing.Size(30, 23);

    this.lblText.TabIndex = 57;

    this.lblText.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;

    //

    // btn_add

    //

    this.btn_add.Location = new System.Drawing.Point(173, 169);

    this.btn_add.Name = "btn_add";

    this.btn_add.Size = new System.Drawing.Size(33, 23);

    this.btn_add.TabIndex = 55;

    this.btn_add.Text = "+";

    this.btn_add.Click += new System.EventHandler(this.btn_add_Click);

    //

    // btn_dot

    //

    this.btn_dot.Location = new System.Drawing.Point(137, 169);

    this.btn_dot.Name = "btn_dot";

    this.btn_dot.Size = new System.Drawing.Size(33, 23);

    this.btn_dot.TabIndex = 54;

    this.btn_dot.Text = ".";

    this.btn_dot.Click += new System.EventHandler(this.btn_dot_Click);

    //

    // btn_sign

    //

    this.btn_sign.Location = new System.Drawing.Point(101, 169);

    this.btn_sign.Name = "btn_sign";

    this.btn_sign.Size = new System.Drawing.Size(33, 23);

    this.btn_sign.TabIndex = 53;

    this.btn_sign.Text = "+/-";

    this.btn_sign.Click += new System.EventHandler(this.btn_sign_Click);

    //

    // btn_0

    //

    this.btn_0.Location = new System.Drawing.Point(62, 169);

    this.btn_0.Name = "btn_0";

    this.btn_0.Size = new System.Drawing.Size(33, 23);

    this.btn_0.TabIndex = 52;

    this.btn_0.Tag = "0";

    this.btn_0.Text = "0";

    this.btn_0.Click += new System.EventHandler(this.btn_0_Click);

    //

    // button22

    //

    this.button22.Location = new System.Drawing.Point(20, 169);

    this.button22.Name = "button22";

    this.button22.Size = new System.Drawing.Size(30, 23);

    this.button22.TabIndex = 51;

    this.button22.Text = "M+";

    this.button22.Click += new System.EventHandler(this.button22_Click);

    //

    // btn_rev

    //

    this.btn_rev.Location = new System.Drawing.Point(209, 139);

    this.btn_rev.Name = "btn_rev";

    this.btn_rev.Size = new System.Drawing.Size(39, 23);

    this.btn_rev.TabIndex = 50;

    this.btn_rev.Text = "1/x";

    this.btn_rev.Click += new System.EventHandler(this.btn_rev_Click);

    //

    // btn_sub

    //

    this.btn_sub.Location = new System.Drawing.Point(173, 139);

    this.btn_sub.Name = "btn_sub";

    this.btn_sub.Size = new System.Drawing.Size(33, 23);

    this.btn_sub.TabIndex = 49;

    this.btn_sub.Text = "-";

    this.btn_sub.Click += new System.EventHandler(this.btn_sub_Click);

    //

    // btn_3

    //

    this.btn_3.Location = new System.Drawing.Point(137, 139);

    this.btn_3.Name = "btn_3";

    this.btn_3.Size = new System.Drawing.Size(33, 23);

    this.btn_3.TabIndex = 48;

    this.btn_3.Tag = "3";

    this.btn_3.Text = "3";

    this.btn_3.Click += new System.EventHandler(this.btn_3_Click);

    //

    // btn_2

    //

    this.btn_2.Location = new System.Drawing.Point(101, 139);

    this.btn_2.Name = "btn_2";

    this.btn_2.Size = new System.Drawing.Size(33, 23);

    this.btn_2.TabIndex = 47;

    this.btn_2.Tag = "2";

    this.btn_2.Text = "2";

    this.btn_2.Click += new System.EventHandler(this.btn_2_Click);

    //

    // btn_1

    //

    this.btn_1.Location = new System.Drawing.Point(65, 139);

    this.btn_1.Name = "btn_1";

    this.btn_1.Size = new System.Drawing.Size(33, 23);

    this.btn_1.TabIndex = 46;

    this.btn_1.Tag = "1";

    this.btn_1.Text = "1";

    this.btn_1.Click += new System.EventHandler(this.btn_1_Click);

    //

    // button16

    //

    this.button16.Location = new System.Drawing.Point(20, 137);

    this.button16.Name = "button16";

    this.button16.Size = new System.Drawing.Size(30, 23);

    this.button16.TabIndex = 45;

    this.button16.Text = "MS";

    this.button16.Click += new System.EventHandler(this.button16_Click);

    //

    // button15

    //

    this.button15.Location = new System.Drawing.Point(209, 106);

    this.button15.Name = "button15";

    this.button15.Size = new System.Drawing.Size(39, 23);

    this.button15.TabIndex = 44;

    this.button15.Text = "%";

    this.button15.Click += new System.EventHandler(this.button15_Click);

    //

    // btn_mul

    //

    this.btn_mul.Location = new System.Drawing.Point(173, 106);

    this.btn_mul.Name = "btn_mul";

    this.btn_mul.Size = new System.Drawing.Size(33, 23);

    this.btn_mul.TabIndex = 43;

    this.btn_mul.Text = "*";

    this.btn_mul.Click += new System.EventHandler(this.btn_mul_Click);

    //

    // btn_6

    //

    this.btn_6.Location = new System.Drawing.Point(137, 106);

    this.btn_6.Name = "btn_6";

    this.btn_6.Size = new System.Drawing.Size(33, 23);

    this.btn_6.TabIndex = 42;

    this.btn_6.Tag = "6";

    this.btn_6.Text = "6";

    this.btn_6.Click += new System.EventHandler(this.btn_6_Click);

    //

    // btn_5

    //

    this.btn_5.Location = new System.Drawing.Point(101, 106);

    this.btn_5.Name = "btn_5";

    this.btn_5.Size = new System.Drawing.Size(33, 23);

    this.btn_5.TabIndex = 41;

    this.btn_5.Tag = "5";

    this.btn_5.Text = "5";

    this.btn_5.Click += new System.EventHandler(this.btn_5_Click);

    //

    // btn_4

    //

    this.btn_4.Location = new System.Drawing.Point(62, 106);

    this.btn_4.Name = "btn_4";

    this.btn_4.Size = new System.Drawing.Size(33, 23);

    this.btn_4.TabIndex = 40;

    this.btn_4.Tag = "4";

    this.btn_4.Text = "4";

    this.btn_4.Click += new System.EventHandler(this.btn_4_Click);

    //

    // btn_equ

    //

    this.btn_equ.Location = new System.Drawing.Point(209, 169);

    this.btn_equ.Name = "btn_equ";

    this.btn_equ.Size = new System.Drawing.Size(39, 23);

    this.btn_equ.TabIndex = 56;

    this.btn_equ.Text = "=";

    this.btn_equ.Click += new System.EventHandler(this.btn_equ_Click);

    //

    // button10

    //

    this.button10.Location = new System.Drawing.Point(20, 105);

    this.button10.Name = "button10";

    this.button10.Size = new System.Drawing.Size(30, 23);

    this.button10.TabIndex = 39;

    this.button10.Text = "MR";

    this.button10.Click += new System.EventHandler(this.button10_Click);

    //

    // btn_sqr

    //

    this.btn_sqr.Location = new System.Drawing.Point(209, 73);

    this.btn_sqr.Name = "btn_sqr";

    this.btn_sqr.Size = new System.Drawing.Size(39, 23);

    this.btn_sqr.TabIndex = 38;

    this.btn_sqr.Text = "sqrt";

    this.btn_sqr.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;

    this.btn_sqr.Click += new System.EventHandler(this.btn_sqr_Click);

    //

    // btn_div

    //

    this.btn_div.Location = new System.Drawing.Point(173, 73);

    this.btn_div.Name = "btn_div";

    this.btn_div.Size = new System.Drawing.Size(33, 23);

    this.btn_div.TabIndex = 37;

    this.btn_div.Text = "/";

    this.btn_div.Click += new System.EventHandler(this.btn_div_Click);

    //

    // btn_9

    //

    this.btn_9.Location = new System.Drawing.Point(137, 73);

    this.btn_9.Name = "btn_9";

    this.btn_9.Size = new System.Drawing.Size(33, 23);

    this.btn_9.TabIndex = 36;

    this.btn_9.Tag = "9";

    this.btn_9.Text = "9";

    this.btn_9.Click += new System.EventHandler(this.btn_9_Click);

    //

    // btn_8

    //

    this.btn_8.Location = new System.Drawing.Point(101, 73);

    this.btn_8.Name = "btn_8";

    this.btn_8.Size = new System.Drawing.Size(33, 23);

    this.btn_8.TabIndex = 35;

    this.btn_8.Tag = "8";

    this.btn_8.Text = "8";

    this.btn_8.Click += new System.EventHandler(this.btn_8_Click);

    //

    // btn_7

    //

    this.btn_7.Location = new System.Drawing.Point(62, 73);

    this.btn_7.Name = "btn_7";

    this.btn_7.Size = new System.Drawing.Size(33, 23);

    this.btn_7.TabIndex = 34;

    this.btn_7.Tag = "7";

    this.btn_7.Text = "7";

    this.btn_7.Click += new System.EventHandler(this.btn_7_Click);

    //

    // txtShow

    //

    this.txtShow.BackColor = System.Drawing.SystemColors.Control;

    this.txtShow.Location = new System.Drawing.Point(8, 19);

    this.txtShow.Name = "txtShow";

    this.txtShow.Size = new System.Drawing.Size(240, 21);

    this.txtShow.TabIndex = 29;

    this.txtShow.Text = "0";

    this.txtShow.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;

    //

    // button4

    //

    this.button4.Location = new System.Drawing.Point(20, 73);

    this.button4.Name = "button4";

    this.button4.Size = new System.Drawing.Size(30, 23);

    this.button4.TabIndex = 33;

    this.button4.Text = "MC";

    this.button4.Click += new System.EventHandler(this.button4_Click);

    //

    // c

    //

    this.c.Location = new System.Drawing.Point(209, 46);

    this.c.Name = "c";

    this.c.Size = new System.Drawing.Size(39, 23);

    this.c.TabIndex = 32;

    this.c.Text = "c";

    this.c.Click += new System.EventHandler(this.c_Click);

    //

    // ce

    //

    this.ce.Location = new System.Drawing.Point(149, 46);

    this.ce.Name = "ce";

    this.ce.Size = new System.Drawing.Size(57, 23);

    this.ce.TabIndex = 31;

    this.ce.Text = "CE";

    this.ce.Click += new System.EventHandler(this.ce_Click);

    //

    // buttonBack

    //

    this.buttonBack.Location = new System.Drawing.Point(64, 46);

    this.buttonBack.Name = "buttonBack";

    this.buttonBack.Size = new System.Drawing.Size(78, 23);

    this.buttonBack.TabIndex = 58;

    this.buttonBack.Text = "Backspace";

    this.buttonBack.Click += new System.EventHandler(this.button1_Click);

    //

    // Form1

    //

    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);

    this.ClientSize = new System.Drawing.Size(264, 211);

    this.Controls.Add(this.buttonBack);

    this.Controls.Add(this.btn_add);

    this.Controls.Add(this.btn_dot);

    this.Controls.Add(this.btn_sign);

    this.Controls.Add(this.btn_0);

    this.Controls.Add(this.button22);

    this.Controls.Add(this.btn_rev);

    this.Controls.Add(this.btn_sub);

    this.Controls.Add(this.btn_3);

    this.Controls.Add(this.btn_2);

    this.Controls.Add(this.btn_1);

    this.Controls.Add(this.button16);

    this.Controls.Add(this.button15);

    this.Controls.Add(this.btn_mul);

    this.Controls.Add(this.btn_6);

    this.Controls.Add(this.btn_5);

    this.Controls.Add(this.btn_4);

    this.Controls.Add(this.btn_equ);

    this.Controls.Add(this.button10);

    this.Controls.Add(this.btn_sqr);

    this.Controls.Add(this.btn_div);

    this.Controls.Add(this.btn_9);

    this.Controls.Add(this.btn_8);

    this.Controls.Add(this.btn_7);

    this.Controls.Add(this.txtShow);

    this.Controls.Add(this.button4);

    this.Controls.Add(this.c);

    this.Controls.Add(this.ce);

    this.Controls.Add(this.lblText);

    this.Menu = this.mainMenu1;

    this.Name = "Form1";

    this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;

    this.Text = "计算器";

    this.ResumeLayout(false);

    }

    #endregion

    public const int NULL = 0;   // 定义操作码

    public const int ADD = 1;     //表示加

    public const int SUB = 2;     //减

    public const int MUL = 3;     //乘

    public const int DIV = 4;    //除

    public const int SQR = 5;    //求平方

    public const int SQRT = 6;   //求平方根

    public const int NODOT  = 0;  // 定义是否点击了小数点,0 为没点

    public const int HASDOT = 1;

    private double res = 0;   // 记录结果数

    private double tmp = 0;   // 当前输入的操作数

    private int opt = NULL;   // 记录操作码

    private int dot = NODOT; // 记录是否点击了小数点,0为没有点

    private int num = 0;  // 记录输入操作数的个数

    private int dotnum = 0;  // 记录小数点部分的个数

    string strOper;            //获取操作符

    private double ShowNum;  //获取txtShow中的文本

    string ShowNum1;

    ///

    /// 应用程序的主入口点。

    ///

    [STAThread]

    static void Main()

    {

    Application.Run(new Form1());

    }

    private void menuItem3_Click(object sender, System.EventArgs e)

    {

    if(txtShow.SelectionLength>0)

    {

    txtShow.Focus();

    txtShow.SelectAll();

    txtShow.Copy();

    }

    }

    private void menuItem5_Click(object sender, System.EventArgs e)

    {

    Help.ShowHelp(this,"C:\\WINDOWS\\Help\\calc.chm");

    }

    private void btn_1_Click(object sender, System.EventArgs e)

    {

    System.Windows.Forms.Button btnTmp;

    double i;

    btnTmp = sender as System.Windows.Forms.Button;

    if (btnTmp != null)

    {

    if (dot == NODOT)

    {

    // 没有点击小数点

    i = double.Parse(btnTmp.Tag.ToString()); //取用户自定义的控件关联数,并转换成double型

    tmp = tmp * 10 + i;

    txtShow.Text = tmp.ToString();   //将其放入文本显示屏啊

    }

    else   // 点击了小数点

    {

    dotnum++;    //记录小数点部分的个数

    // 生成小数部分的新的数值

    i = double.Parse(btnTmp.Tag.ToString()) / System.Math.Pow(10,dotnum);

    tmp = tmp + i;  //将小数点后的值加到当前操做数

    txtShow.Text = tmp.ToString();

    }

    }

    }

    private void btn_2_Click(object sender, System.EventArgs e)

    {

    System.Windows.Forms.Button btnTmp;

    double i;

    btnTmp = sender as System.Windows.Forms.Button;

    if (btnTmp != null)

    {

    if (dot == NODOT)

    {

    // 没有点击小数点

    i = double.Parse(btnTmp.Tag.ToString()); //取用户自定义的控件关联数,并转换成double型

    tmp = tmp * 10 + i;

    txtShow.Text = tmp.ToString();   //将其放入文本显示屏啊

    }

    else   // 点击了小数点

    {

    dotnum++;    //记录小数点部分的个数

    // 生成小数部分的新的数值

    i = double.Parse(btnTmp.Tag.ToString()) / System.Math.Pow(10,dotnum);

    tmp = tmp + i;  //将小数点后的值加到当前操做数

    txtShow.Text = tmp.ToString();

    }

    }

    }

    private void btn_3_Click(object sender, System.EventArgs e)

    {

    System.Windows.Forms.Button btnTmp;

    double i;

    btnTmp = sender as System.Windows.Forms.Button;

    if (btnTmp != null)

    {

    if (dot == NODOT)

    {

    // 没有点击小数点

    i = double.Parse(btnTmp.Tag.ToString()); //取用户自定义的控件关联数,并转换成double型

    tmp = tmp * 10 + i;

    txtShow.Text = tmp.ToString();   //将其放入文本显示屏啊

    }

    else   // 点击了小数点

    {

    dotnum++;    //记录小数点部分的个数

    // 生成小数部分的新的数值

    i = double.Parse(btnTmp.Tag.ToString()) / System.Math.Pow(10,dotnum);

    tmp = tmp + i;  //将小数点后的值加到当前操做数

    txtShow.Text = tmp.ToString();

    }

    }

    }

    private void btn_4_Click(object sender, System.EventArgs e)

    {

    System.Windows.Forms.Button btnTmp;

    double i;

    btnTmp = sender as System.Windows.Forms.Button;

    if (btnTmp != null)

    {

    if (dot == NODOT)

    {

    // 没有点击小数点

    i = double.Parse(btnTmp.Tag.ToString()); //取用户自定义的控件关联数,并转换成double型

    tmp = tmp * 10 + i;

    txtShow.Text = tmp.ToString();   //将其放入文本显示屏啊

    }

    else   // 点击了小数点

    {

    dotnum++;    //记录小数点部分的个数

    // 生成小数部分的新的数值

    i = double.Parse(btnTmp.Tag.ToString()) / System.Math.Pow(10,dotnum);

    tmp = tmp + i;  //将小数点后的值加到当前操做数

    txtShow.Text = tmp.ToString();

    }

    }

    }

    private void btn_5_Click(object sender, System.EventArgs e)

    {

    System.Windows.Forms.Button btnTmp;

    double i;

    btnTmp = sender as System.Windows.Forms.Button;

    if (btnTmp != null)

    {

    if (dot == NODOT)

    {

    // 没有点击小数点

    i = double.Parse(btnTmp.Tag.ToString()); //取用户自定义的控件关联数,并转换成double型

    tmp = tmp * 10 + i;

    txtShow.Text = tmp.ToString();   //将其放入文本显示屏啊

    }

    else   // 点击了小数点

    {

    dotnum++;    //记录小数点部分的个数

    // 生成小数部分的新的数值

    i = double.Parse(btnTmp.Tag.ToString()) / System.Math.Pow(10,dotnum);

    tmp = tmp + i;  //将小数点后的值加到当前操做数

    txtShow.Text = tmp.ToString();

    }

    }

    }

    private void btn_6_Click(object sender, System.EventArgs e)

    {

    System.Windows.Forms.Button btnTmp;

    double i;

    btnTmp = sender as System.Windows.Forms.Button;

    if (btnTmp != null)

    {

    if (dot == NODOT)

    {

    // 没有点击小数点

    i = double.Parse(btnTmp.Tag.ToString()); //取用户自定义的控件关联数,并转换成double型

    tmp = tmp * 10 + i;

    txtShow.Text = tmp.ToString();   //将其放入文本显示屏啊

    }

    else   // 点击了小数点

    {

    dotnum++;    //记录小数点部分的个数

    // 生成小数部分的新的数值

    i = double.Parse(btnTmp.Tag.ToString()) / System.Math.Pow(10,dotnum);

    tmp = tmp + i;  //将小数点后的值加到当前操做数

    txtShow.Text = tmp.ToString();

    }

    }

    }

    private void btn_7_Click(object sender, System.EventArgs e)

    {

    System.Windows.Forms.Button btnTmp;

    double i;

    btnTmp = sender as System.Windows.Forms.Button;

    if (btnTmp != null)

    {

    if (dot == NODOT)

    {

    // 没有点击小数点

    i = double.Parse(btnTmp.Tag.ToString()); //取用户自定义的控件关联数,并转换成double型

    tmp = tmp * 10 + i;

    txtShow.Text = tmp.ToString();   //将其放入文本显示屏啊

    }

    else   // 点击了小数点

    {

    dotnum++;    //记录小数点部分的个数

    // 生成小数部分的新的数值

    i = double.Parse(btnTmp.Tag.ToString()) / System.Math.Pow(10,dotnum);

    tmp = tmp + i;  //将小数点后的值加到当前操做数

    txtShow.Text = tmp.ToString();

    }

    }

    }

    private void btn_8_Click(object sender, System.EventArgs e)

    {

    System.Windows.Forms.Button btnTmp;

    double i;

    btnTmp = sender as System.Windows.Forms.Button;

    if (btnTmp != null)

    {

    if (dot == NODOT)

    {

    // 没有点击小数点

    i = double.Parse(btnTmp.Tag.ToString()); //取用户自定义的控件关联数,并转换成double型

    tmp = tmp * 10 + i;

    txtShow.Text = tmp.ToString();   //将其放入文本显示屏啊

    }

    else   // 点击了小数点

    {

    dotnum++;    //记录小数点部分的个数

    // 生成小数部分的新的数值

    i = double.Parse(btnTmp.Tag.ToString()) / System.Math.Pow(10,dotnum);

    tmp = tmp + i;  //将小数点后的值加到当前操做数

    txtShow.Text = tmp.ToString();

    }

    }

    }

    private void btn_9_Click(object sender, System.EventArgs e)

    {

    System.Windows.Forms.Button btnTmp;

    double i;

    btnTmp = sender as System.Windows.Forms.Button;

    if (btnTmp != null)

    {

    if (dot == NODOT)

    {

    // 没有点击小数点

    i = double.Parse(btnTmp.Tag.ToString()); //取用户自定义的控件关联数,并转换成double型

    tmp = tmp * 10 + i;

    txtShow.Text = tmp.ToString();   //将其放入文本显示屏啊

    }

    else   // 点击了小数点

    {

    dotnum++;    //记录小数点部分的个数

    // 生成小数部分的新的数值

    i = double.Parse(btnTmp.Tag.ToString()) / System.Math.Pow(10,dotnum);

    tmp = tmp + i;  //将小数点后的值加到当前操做数

    txtShow.Text = tmp.ToString();

    }

    }

    }

    private void btn_0_Click(object sender, System.EventArgs e)

    {

    System.Windows.Forms.Button btnTmp;

    double i;

    btnTmp = sender as System.Windows.Forms.Button;

    if (btnTmp != null)

    {

    if (dot == NODOT)

    {

    // 没有点击小数点

    i = double.Parse(btnTmp.Tag.ToString()); //取用户自定义的控件关联数,并转换成double型

    tmp = tmp * 10 + i;

    txtShow.Text = tmp.ToString();   //将其放入文本显示屏啊

    }

    else   // 点击了小数点

    {

    dotnum++;    //记录小数点部分的个数

    // 生成小数部分的新的数值

    i = double.Parse(btnTmp.Tag.ToString()) / System.Math.Pow(10,dotnum);

    tmp = tmp + i;  //将小数点后的值加到当前操做数

    txtShow.Text = tmp.ToString();

    }

    }

    }

    private void btn_Oper(Button tmp1)

    {

    strOper=tmp1.Text;

    switch (strOper)

    {

    case "/":       //除法运算

    if(opt!=NULL&&opt!=DIV)

    {

    calc();

    }

    opt = DIV;

    if (num != 0)  //判断操作数的个数,如果两个就做二元运算

    {

    if (tmp != 0)

    res = res / tmp;

    }

    else

    res = tmp;

    num++;

    tmp = 0;

    txtShow.Text = res.ToString();

    dot = NODOT;

    break;

    case "*":

    // 乘法运算

    if(opt!=NULL&&opt!=MUL)

    {

    calc();

    }

    opt = MUL;

    if (num!= 0 )     //判断操作数的个数,如果两个就做二元运算

    {

    if(tmp!=0)

    res = res * tmp;

    }

    else

    res = tmp;

    num++;

    tmp = 0;

    txtShow.Text = res.ToString();

    dot = NODOT;

    break;

    case "+":            //加法运算

    if(opt!=NULL&&opt!=ADD)

    {

    calc();

    }

    opt = ADD;

    if (num != 0)    //判断操作数的个数,如果两个就做二元运算

    res = res + tmp;

    else

    res = tmp;

    num++;

    tmp = 0;

    txtShow.Text = res.ToString();

    dot = NODOT;

    break;

    case "-":        //减法运算

    if(opt!=NULL&&opt!=SUB)

    {

    calc();

    }

    opt = SUB;

    if (num != 0)    //判断操作数的个数,如果两个就做二元运算

    res = res - tmp;

    else

    res = tmp;

    num++;

    tmp = 0;

    txtShow.Text = res.ToString();

    dot = NODOT;

    break;

    case "sqrt":     //平方根运算

    if(opt!=NULL)

    {

    calc();

    }

    //opt=SQRT;

    if (tmp > 0)  //要求操作数大于0

    {

    res = Math.Sqrt(tmp);

    //res=tmp;

    }

    else if(res>0)

    res= Math.Sqrt(res);

    txtShow.Text =res.ToString();

    num++;

    tmp=0;

    dot = NODOT;

    break;

    case "1/x":  //倒数运算

    if(opt!=NULL)

    {

    calc();

    }

    if (tmp != 0)

    {

    res = 1 / tmp;

    //res=tmp;

    }

    else

    res=1/res;

    txtShow.Text = res.ToString();

    tmp=0;

    dot = NODOT;

    break;

    case ".":

    // 点击了小数点

    if(dot==HASDOT)

    return;

    else

    {

    dot = HASDOT;

    dotnum = 0;

    }

    break;

    case "+/-":

    // 点击了符号运算

    if(tmp!=0)

    {

    tmp = -tmp;

    txtShow.Text = tmp.ToString();

    }

    else

    {

    res=-res;

    //res=tmp;

    txtShow.Text = res.ToString();

    }

    dot = NODOT;

    break;

    case "CE":     //清除运算

    res = 0;   // 记录结果数

    tmp = 0;   // 当前输入的操作数

    opt = NULL;   // 记录操作码

    dot = NODOT; // 记录是否点击了小数点

    num = 0;  // 记录输入操作数的个数

    dotnum = 0;  // 记录小数点部分的个数

    txtShow.Text="";

    break;

    case "c":         //清除运算

    res = 0;   // 记录结果数

    tmp = 0;   // 当前输入的操作数

    opt = NULL;   // 记录操作码

    dot = NODOT; // 记录是否点击了小数点

    num = 0;  // 记录输入操作数的个数

    dotnum = 0;  // 记录小数点部分的个数

    txtShow.Text="0";

    break;

    case "%":

    if(tmp!=0)

    {

    if(opt == NULL)

    {

    tmp = tmp/100;

    }

    if(opt != NULL)

    {

    tmp = res*tmp/100;

    }

    txtShow.Text = tmp.ToString();

    }

    else

    {

    res = res/100;

    txtShow.Text = res.ToString();

    }

    dot = NODOT;

    break;

    }

    }

    private void btn_sign_Click(object sender, System.EventArgs e)

    {

    btn_Oper(btn_sign);

    }

    private void btn_dot_Click(object sender, System.EventArgs e)

    {

    btn_Oper(btn_dot);

    }

    private void btn_add_Click(object sender, System.EventArgs e)

    {

    btn_Oper(btn_add);

    }

    private void btn_equ_Click(object sender, System.EventArgs e)

    {

    calc();

    }

    private void calc()

    {

    // 生成结果

    if (num == 0 )    //是否有操作数,没有就返回0

    {

    res = 0;

    tmp = 0;

    txtShow.Text = res.ToString();

    return;

    }

    switch (opt)  //找到对应的运算符进行计算

    {

    // 加法

    case ADD:

    res = res + tmp;

    break;

    // 减法

    case SUB:

    res = res - tmp;

    break;

    // 乘法

    case MUL:

    res = res * tmp;

    break;

    // 除法

    case DIV:

    res = res / tmp;

    break;

    //百分比

    //        case SQR:

    //         res = tmp/100;

    //         break;

    //平方根

    case SQRT:

    res = System.Math.Sqrt(tmp);

    break;

    default:

    return;

    }

    txtShow.Text = res.ToString();   //结果输出到文本显示屏

    opt = NULL;  //运算符清空

    tmp=0;

    dot = NODOT;

    res = 0;

    num = 0;

    }

    private void btn_sub_Click(object sender, System.EventArgs e)

    {

    btn_Oper(btn_sub);

    }

    private void btn_mul_Click(object sender, System.EventArgs e)

    {

    btn_Oper(btn_mul);

    }

    private void btn_div_Click(object sender, System.EventArgs e)

    {

    btn_Oper(btn_div);

    }

    private void ce_Click(object sender, System.EventArgs e)

    {

    btn_Oper(ce);

    }

    private void c_Click(object sender, System.EventArgs e)

    {

    btn_Oper(c);

    }

    private void btn_sqr_Click(object sender, System.EventArgs e)

    {

    btn_Oper(btn_sqr);

    }

    private void button15_Click(object sender, System.EventArgs e)

    {

    btn_Oper(button15);

    }

    private void btn_rev_Click(object sender, System.EventArgs e)

    {

    btn_Oper(btn_rev);

    }

    private void button4_Click(object sender, System.EventArgs e)

    {

    lblText.Text = "";

    ShowNum=0;

    tmp = 0;

    }

    private void button10_Click(object sender, System.EventArgs e)

    {

    if(ShowNum!=0)

    {

    txtShow.Text = ShowNum.ToString();

    }

    tmp=0;

    }

    private void button16_Click(object sender, System.EventArgs e)

    {

    if(txtShow.Text!="0")

    {

    ShowNum = tmp;

    lblText.Text = "M";

    tmp = 0;

    }

    }

    private void button22_Click(object sender, System.EventArgs e)

    {

    ShowNum=ShowNum+tmp;

    txtShow.Text = ShowNum.ToString();

    tmp=0;

    }

    private void menuItemLink_Click(object sender, System.EventArgs e)

    {

    MessageBox.Show("By - Looky.Tenfu","关于");

    }

    private void menuItemHelp_Click(object sender, System.EventArgs e)

    {

    Help.ShowHelp(this,"C:\\WINDOWS\\Help\\calc.chm");

    }

    private void button1_Click(object sender, System.EventArgs e)

    {

    if(txtShow.Text.Length > 0)

    {

    ShowNum1=txtShow.Text;

    txtShow.Text = ShowNum1.Substring(0,ShowNum1.Length-1);

    tmp=0;

    }

    if(txtShow.Text.Length == 0)

    {

    txtShow.Text="0";

    tmp=0;

    }

    }

    }

    }

    有任何问题,可在下面回复!呵呵......

    展开全文
  • C#编写计算器,可接受用户输入带有运算符的算式并给出结果 using System; class Program { public static void Main (string[] args) { string strInput; string num1 = ""; string num2 = ""; int op = 0; ...

    C#编写计算器,可接受用户输入带有运算符的算式并给出结果


    不考虑后期的维护,只是C#面向初学者学习,注重过程的代码,希望有大神能够提供更简洁的代码,共同进步学习,我为人人,人人为我!

    using System;
    class Program 
    {
        public static void Main (string[] args) {
        string strInput;
        string num1 = "";
        string num2 = "";
        int op = 0;
        float a, b, result;
        Console.WriteLine("Enter a formula in the form [INT][OPERATOR[INT]:");
        strInput = Console.ReadLine();
    
        for (int i = 0; i<strInput.Length; i++)
        {
          if (strInput[i] == '+')
          {
            op = i;
          }
          else if(strInput[i] == '-')
          {
            op = i;
          }
          else if (strInput[i] == '*')
          {
            op = i;
          }
          else if (strInput[i] == '/')
          {
            op = i;
          }
        }
    
        for (int j = 0; j < strInput.Length; j++)
        {
          if (j < op)
          {
            num1 += strInput[j];
          }
          else if (j > op)
          {
            num2 += strInput[j];
          }
        }
                
        if (strInput[op] == '+')
        {
          a = Convert.ToSingle(num1);
          b = Convert.ToSingle(num2);
          result = a + b;
          result = (float)Math.Round(result, 3);
          Console.WriteLine($"{num1} + {num2} = {result}");
        }
        else if(strInput[op] == '-')
        {
          a = Convert.ToSingle(num1);
          b = Convert.ToSingle(num2);
          result = a - b;
          result = (float)Math.Round(result, 3);
          Console.WriteLine($"{num1} - {num2} = {result}");
        }
        else if(strInput[op] == '*')
        {
          a = Convert.ToSingle(num1);
          b = Convert.ToSingle(num2);
          result = a * b;
          result = (float)Math.Round(result, 3);
          Console.WriteLine($"{num1} * {num2} = {result}");
        }
        else if(strInput[op] == '/')
        {
          a = Convert.ToSingle(num1);
          b = Convert.ToSingle(num2);
          result = a / b;
          result = (float)Math.Round(result, 3);
          Console.WriteLine($"{num1} / {num2} = {result}");
        }
      }
    }
    
    
    
    

    我同时也把代码上传了,感兴趣的朋友可以下载。https://download.csdn.net/download/weixin_47045246/33167873

    展开全文
  • 1.参照Windows系统提供的计算器功能,制作一个自己的计算器,至少能完成数据的加减乘除的基本功能。 2.控件的焦点以及Tab键的设置和使用 3.多个控件(按钮)事件的共享 4.键盘的事件的应用 创建主体框架:主要是对...
  • C#语言编写计算器

    千次阅读 2016-06-19 18:25:28
    模仿windows操作系统附件中的计算器样式进行设计,要设计基本的菜单项(快捷键、热键、和分割线等)       功能要求:实现如下图所示的功能键   设置热键方法如下:   先用窗体项目做出如图...
    

    模仿windows操作系统附件中的计算样式进行设计要设计基本的菜单项(快捷键、热键、和分割线等)

            

     

     

    功能要求:实现如下图所示的功能

     



    设置热键方法如下:

     

    先用窗体项目做出如图窗体

    右击下拉菜单项

     

    点击编辑项设置热键

     

    点击DropdownItems集合

    在这里设置热键,以此类推;

     

     

     

    全部设置完毕后如图

     

     

    然后点击计算器窗体

    初始化显示文本框为空;为0~9以及小数点添加操作数监听,

    为操作符添加操作符监听以及删除、退格、清空分别添加监听器;

    全部代码如下:

    <span style="font-family:Comic Sans MS;font-size:14px;">using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            //保存用户所按的运算符
            private string s;
            //保存用户输入的运算数
            private double x, y;
            //运算符按钮对象
            private Button btn;
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                textBox1.Text = "";
            }
            private void buttond_Click(object sender, EventArgs e)
            {
                btn = (Button)sender;
                textBox1.Text += btn.Text;
            }
            private void buttonop_Click(object sender, EventArgs e)
            {
                btn = (Button)sender;
                if(btn.Name!="btn_Equal")
                {
                    x = Convert.ToDouble(textBox1.Text);
                    textBox1.Text = "";
                    s = btn.Name;
                    switch (s)
                    {
                        case "btn_Recip":
                            textBox1.Text = "1/" + x.ToString() + "=" + (1/x).ToString();
                            break;
                        case "btn_Sqrt":
                            textBox1.Text = "√" + x.ToString() + "=" + Math.Sqrt(x).ToString();
                            break;
                    }
                }
                else
                {
                    y = Convert.ToDouble(textBox1.Text);
                    switch(s)
                    {
                        case"btn_Add":
                            textBox1.Text = x.ToString()+"+"+y.ToString()+"="+(x + y).ToString();
                            break;
                        case "btn_Sub":
                            textBox1.Text = x.ToString() + "-" + y.ToString() + "=" + (x - y).ToString();
                            break;
                        case "btn_Mul":
                            textBox1.Text = x.ToString() + "*" + y.ToString() + "=" + (x * y).ToString();
                            break;
                        case "btn_Div":
                            if (y == 0)
                            {
                                MessageBox.Show("除零错误!!!", "信息提示", MessageBoxButtons.OK);
                            }
                            else
                                textBox1.Text = x.ToString() + "/" + y.ToString() + "=" + (x / y).ToString();
                            break;
                        case "btn_Mod":
                            textBox1.Text = x.ToString() + "%" + y.ToString() + "=" + (x % y).ToString();
                            break;
                    }
                }
            }
            private void changeSign(object sender, EventArgs e)        
            {            
                double storNum;             
                if (textBox1.Text.Length > 0)  
                {
                    storNum = double.Parse(textBox1.Text);                 
                    storNum *= -1;               
                    textBox1.Text = storNum.ToString();           
                }            
                btn_Equal.Select();       
            }
            private void btnDeleteSign_Clicked(object sender, EventArgs e)
            {
                 
            }
            private void btnDeleteAll_Clicked(object sender, EventArgs e)
            {
                textBox1.Text = "";
            }
            private void btnDelete1_Clicked(object sender, EventArgs e)
            {
                this.textBox1.Text = this.textBox1.Text.Substring(0, this.textBox1.Text.Length - 1);
                if(this.textBox1.Text=="")
                {
                    this.textBox1.Text = "";
                }
            }
        }
    }</span>

    最后执行结果如下:

     


    展开全文
  • C#写的计算器,代码注释的明明白白。只包括基础加减乘除,可以连续计算
  • 初学者编写的,比较简单。主要是简单的语句编写。 有高手请指点一下。本人将非常感谢。
  • 如何用c#编写一个简单的计算器

    千次阅读 2020-04-29 15:29:13
    分析: 1.设计好界面 2.必须有两个textbox来输出结果和算术式 3.具备基本的数字和运算符 4....创建项目,设计界面 在窗体中添加两个textbox控件和若干的button按钮,并对... } 这样一个简单的计算器小程序就编写完成了。
  • C#编写计算器,界面清晰,代码简洁易懂,希望对大家有点作用。
  • C#编写计算器程序

    2009-08-28 21:29:56
    C#编写计算器程序。用C#写的比较基础的windows Form 程序,该计算器实现了基础的数学运算,如加,减,乘,除等任务.主要是通过该程序学习vs.net的
  • C#实现计算器(附Java版)

    千次阅读 2021-03-15 13:42:59
    嘤嘤嘤~~ 说到写计算器,我还算有过经验,之前用Java的GUI写过,那个比这个做的复杂多了,当前写的C#,目前只能实现单个运算符的运算,多个的暂时没考虑,不过肯定是可以实现的。我的Java版实现了,一会放上链接,...
  • C#实现简易计算器(附带源码)

    千次阅读 多人点赞 2020-04-29 21:59:05
    //窗体居中显示 this.Text = "计算器"; this.FormBorderStyle = FormBorderStyle.FixedToolWindow; textBox1.ReadOnly = true;//文本框只读 textBox2.TabIndex = 0;//光标焦点在textbox2中 } private void button1_...
  • C#在VS2005平台上面编写计算器小程序,程序代码较简单,仅供参考。 本人也是初学者,讨论交流请加QQ305566159
  • C#计算器源码

    2017-11-29 11:21:12
    C#计算器源码C#计算器源码C#计算器源码C#计算器源码C#计算器源码C#计算器源码C#计算器源码C#计算器源码C#计算器源码C#计算器源码C#计算器源码
  • C#计算器

    2015-12-31 12:38:02
    C#计算器
  • C#实现简易计算器

    2021-03-29 14:17:42
    C#编写一个简易计算器,供大家参考,具体c#教程内容如下 界面 代码 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq;...
  • 初学者c#编写计算器代码,适合初学者看。

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 4,012
精华内容 1,604
关键字:

c#编写计算器

c# 订阅