资源简介

用C# WinForm写的计算器,在前作基础上使用了堆栈,重写了部分代码,减少了布尔参数的数量,功能包括四则运算和存储记忆、退格、清零等,可以实现连续运算,测试基本无BUG

资源截图

代码片段和文件信息

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 CalculatorStatck
{
    public partial class Calculator : Form
    {
        public Calculator()
        {
            InitializeComponent();
        }

        private string _testbox;
        private bool _inset = false;
        private double _memory = 0;
        private string _lastoper = ““;
        private string _secondNum = ““;
        Stack calc = new Stack();



        private void DigitBtn_Click(object sender EventArgs e)//数字类按钮输入
        {
            string s = ((Button)sender).Text.ToString();
            char[] ids = s.ToCharArray();
            ProcessKey(ids[0]);
        }

        private void ProcessKey(char c)//处理重输入
        {
            if (Inset == false)
            {
                Testbox = string.Empty;
                Inset = true;
            }
            AddToDisplay(c);
        }

        private bool Inset//输入布尔判定
        {
            get
            {
                return _inset;

            }
            set
            {
                _inset = value;
            }
        }
        private string Testbox
        {
            get
            {
                return _testbox;

            }
            set
            {
                _testbox = value;
            }
        }

        private Double Memory//记忆
        {
            get
            {
                if (_memory == 0)
                    return 0;
                else
                    return _memory;
            }
            set
            {
                _memory = (0);
            }
        }

        private void OperBtn_Click(object sender EventArgs e)//运算符类按钮输入
        {
            ProcessOperation(((Button)sender).Name.ToString());
        }

        private void AddToDisplay(char c)
        {
            if (c == ‘.‘)
            {
                if (Testbox.IndexOf(‘.‘ 0) >= 0)  //存在小数点
                    return;
                Testbox = Testbox + c;
            }
            else
            {
                if (c >= ‘0‘ && c <= ‘9‘)
                {
                    if (textBox1.Text == “0“ || _inset == false)
                        Testbox = String.Empty;
                    Testbox = Testbox + c;
                    _inset = true;
                }
                else
                    if (c == ‘\b‘)  //退格
                    {
                        if (Testbox.Length <= 1)
                            Testbox = String.Empty;
                        else
                        {
                            int i = Testbox.Length;
                            Testbox = Testbox.Remove(i - 1 1);  //移除最后一位
                        }
                    }

            }

            U

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      17408  2012-04-24 13:57  CalculatorStatck\CalculatorStatck\bin\Debug\CalculatorStatck.exe

     文件      34304  2012-04-24 13:57  CalculatorStatck\CalculatorStatck\bin\Debug\CalculatorStatck.pdb

     文件      11600  2012-04-24 16:55  CalculatorStatck\CalculatorStatck\bin\Debug\CalculatorStatck.vshost.exe

     文件        490  2009-08-31 00:40  CalculatorStatck\CalculatorStatck\bin\Debug\CalculatorStatck.vshost.exe.manifest

     文件       3691  2012-04-24 09:37  CalculatorStatck\CalculatorStatck\CalculatorStatck.csproj

     文件      10616  2012-04-24 13:57  CalculatorStatck\CalculatorStatck\Form1.cs

     文件      18398  2012-04-24 13:57  CalculatorStatck\CalculatorStatck\Form1.Designer.cs

     文件       5817  2012-04-24 13:57  CalculatorStatck\CalculatorStatck\Form1.resx

     文件        180  2012-04-24 13:57  CalculatorStatck\CalculatorStatck\obj\x86\Debug\CalculatorStatck.Calculator.resources

     文件        972  2012-04-24 16:55  CalculatorStatck\CalculatorStatck\obj\x86\Debug\CalculatorStatck.csproj.FileListAbsolute.txt

     文件      17408  2012-04-24 13:57  CalculatorStatck\CalculatorStatck\obj\x86\Debug\CalculatorStatck.exe

     文件      34304  2012-04-24 13:57  CalculatorStatck\CalculatorStatck\obj\x86\Debug\CalculatorStatck.pdb

     文件        180  2012-04-24 09:37  CalculatorStatck\CalculatorStatck\obj\x86\Debug\CalculatorStatck.Properties.Resources.resources

     文件       4440  2012-04-24 16:55  CalculatorStatck\CalculatorStatck\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       6292  2012-04-24 13:57  CalculatorStatck\CalculatorStatck\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件        344  2012-04-24 13:57  CalculatorStatck\CalculatorStatck\obj\x86\Debug\GenerateResource.read.1.tlog

     文件        832  2012-04-24 13:57  CalculatorStatck\CalculatorStatck\obj\x86\Debug\GenerateResource.write.1.tlog

     文件        502  2012-04-24 09:37  CalculatorStatck\CalculatorStatck\Program.cs

     文件       1378  2012-04-24 09:33  CalculatorStatck\CalculatorStatck\Properties\AssemblyInfo.cs

     文件       2882  2012-04-24 09:33  CalculatorStatck\CalculatorStatck\Properties\Resources.Designer.cs

     文件       5612  2012-04-24 09:33  CalculatorStatck\CalculatorStatck\Properties\Resources.resx

     文件       1101  2012-04-24 09:33  CalculatorStatck\CalculatorStatck\Properties\Settings.Designer.cs

     文件        249  2012-04-24 09:33  CalculatorStatck\CalculatorStatck\Properties\Settings.settings

     文件        890  2012-04-24 09:33  CalculatorStatck\CalculatorStatck.sln

    ..A..H.     19456  2012-04-24 14:17  CalculatorStatck\CalculatorStatck.suo

     目录          0  2012-04-24 09:33  CalculatorStatck\CalculatorStatck\obj\x86\Debug\TempPE

     目录          0  2012-04-24 16:55  CalculatorStatck\CalculatorStatck\obj\x86\Debug

     目录          0  2012-04-24 09:37  CalculatorStatck\CalculatorStatck\bin\Debug

     目录          0  2012-04-24 09:33  CalculatorStatck\CalculatorStatck\obj\x86

     目录          0  2012-04-24 09:33  CalculatorStatck\CalculatorStatck\bin

............此处省略7个文件信息

评论

共有 条评论