• 大小: 342KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-27
  • 语言: C#
  • 标签: 计算器  c#  

资源简介

程序采用c#做计算器实现, 仿windows计算器。实现了基本的计算器功能。

资源截图

代码片段和文件信息

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 Calculator
{
    public partial class Form1 : Form
    {

        //变量申明

        //记录输入字符串
        private string inputString = ““;

        //存储操作数
        private Stack Numbers = new Stack();

        //记录第一个操作符
        private string firstOperator = ““;

        //记录第二个操作符
        private string secondOperator = ““;

        //记录第三个操作符
        private string thirdOperator = ““;

        //记录操作符数目
        private int operateCount = 0;

        //“=”按钮是否按下
        private bool EqualDown = false;

        //记录是否按下正负号
        private bool OpOperator = false;

        //最后一个运算符
        private string finalOperator = ““;


        //最后一个操作数
        private double finalNumber = 0;

        //存储在内存中的数据
        private double MemoryNumber = 0;

        public Form1()
        {
            InitializeComponent();
        }

        private void McBtn_Click(object sender EventArgs e)
        {
            //内存数据清零
                MemoryNumber = 0;

        }

        private void MrBtn_Click(object sender EventArgs e)
        {
            //读取内存数据
            InputTextBox.Text = MemoryNumber.ToString();
        }

        private void MsBtn_Click(object sender EventArgs e)
        {
            //如果输入不为0,将数据存入内存中去
            if (inputString.Length > 0)
            {
                MemoryNumber = Convert.ToDouble(inputString);
            }
            else
            {
                //如果输入为0,不做任何操作
                MemoryNumber = 0;
            }


        }

        private void MPlussBtn_Click(object sender EventArgs e)
        {
            //将内存中数据加上当前数据值,并重新存储
            if (inputString.Length != 0)
            {
                MemoryNumber = MemoryNumber + Convert.ToDouble(inputString);
            }
        }

        private void MminusBtn_Click(object sender EventArgs e)
        {
            //内存数据值减去当前数据值,并重新存储
            if (inputString.Length != 0)
            {
                MemoryNumber = MemoryNumber - Convert.ToDouble(inputString);
            }
        }

        
        private void BackBtn_Click(object sender EventArgs e)
        {

            if (!EqualDown)
            {
                if (inputString.Length == 0)
                {
                    InputTextBox.Text = “0“;
                }

                else
                {
                    int count = inputString.Length;

                    string myString = ““;

                    for (int i = 0; i < count - 1; i++)
                    {
                        myString += inputString.ElementAt(i);
                    }

                    inputString = myString;

                    InputTextBox.Text = inputString;

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2011-11-01 22:31  Calculator\
     目录           0  2011-11-02 11:41  Calculator\Calculator\
     文件        4304  2011-11-02 11:44  Calculator\Calculator\Calculator.csproj
     文件       22621  2011-11-02 11:44  Calculator\Calculator\Form1.Designer.cs
     文件       34066  2011-11-02 12:47  Calculator\Calculator\Form1.cs
     文件       41677  2011-11-02 11:44  Calculator\Calculator\Form1.resx
     文件        2538  2011-11-02 11:54  Calculator\Calculator\Form2.Designer.cs
     文件         362  2011-11-02 11:48  Calculator\Calculator\Form2.cs
     文件        5817  2011-11-02 11:47  Calculator\Calculator\Form2.resx
     文件         491  2011-10-27 19:17  Calculator\Calculator\Program.cs
     目录           0  2011-10-27 19:17  Calculator\Calculator\Properties\
     文件        1352  2011-10-27 19:17  Calculator\Calculator\Properties\AssemblyInfo.cs
     文件        3101  2011-11-02 11:41  Calculator\Calculator\Properties\Resources.Designer.cs
     文件        6191  2011-11-02 11:41  Calculator\Calculator\Properties\Resources.resx
     文件        1095  2011-10-27 19:17  Calculator\Calculator\Properties\Settings.Designer.cs
     文件         249  2011-10-27 19:17  Calculator\Calculator\Properties\Settings.settings
     目录           0  2011-11-02 11:41  Calculator\Calculator\Resources\
     文件       45010  2011-11-02 11:41  Calculator\Calculator\Resources\cc.jpg
     目录           0  2011-11-01 16:14  Calculator\Calculator\bin\
     目录           0  2011-11-01 23:36  Calculator\Calculator\bin\Debug\
     文件      109056  2011-11-02 12:28  Calculator\Calculator\bin\Debug\Calculator.exe
     文件       54784  2011-11-02 12:28  Calculator\Calculator\bin\Debug\Calculator.pdb
     文件       11600  2011-11-02 12:13  Calculator\Calculator\bin\Debug\Calculator.vshost.exe
     文件         490  2010-03-17 22:39  Calculator\Calculator\bin\Debug\Calculator.vshost.exe.manifest
     目录           0  2011-11-02 12:48  Calculator\Calculator\bin\Release\
     目录           0  2011-10-27 19:17  Calculator\Calculator\obj\
     目录           0  2011-10-27 19:17  Calculator\Calculator\obj\x86\
     目录           0  2011-11-02 12:28  Calculator\Calculator\obj\x86\Debug\
     文件       36998  2011-11-02 11:44  Calculator\Calculator\obj\x86\Debug\Calculator.Form1.resources
     文件         180  2011-11-02 11:47  Calculator\Calculator\obj\x86\Debug\Calculator.Form2.resources
     文件       45659  2011-11-02 11:44  Calculator\Calculator\obj\x86\Debug\Calculator.Properties.Resources.resources
............此处省略14个文件信息

评论

共有 条评论