首页 > 编程语言 >每日随笔——c#编写计算器

每日随笔——c#编写计算器

时间:2023-10-21 22:44:18浏览次数:37  
标签:c# Text void object private textBox1 EventArgs 计算器 随笔

今天我使用c#语言开始编写计算器小程序

 

 

namespace WinFormsApp1
{
    public partial class Form1 : Form
    {
        double a = 0;
        double b = 0;
        bool c = false;
        string d;

        public Form1()
        {
            InitializeComponent();
        }

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

        }

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

        }

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

        }

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

        }

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

        }

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

        }

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

        }

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

        }

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

        }

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

        }

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

        }

        private void button12_Click(object sender, EventArgs e)
        {

            c = true;
            b = double.Parse(textBox1.Text);
            d = "-";

        }

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

        }

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

        }

        private void button15_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 "X2": a = b * b; break;
                case "sqrt": a = Math.Sqrt(b); break;
                case "log": a = Math.Log(double.Parse(textBox1.Text),b); break;
                case "ln": a = Math.Log(b,Math.E); break;

            }
            textBox1.Text = a + "";
            c = true;

        }

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

        private void button17_Click(object sender, EventArgs e)
        {
            c = true;
            b = double.Parse(textBox1.Text);
            d = "X2";

        }

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

        }

        private void button19_Click(object sender, EventArgs e)
        {
            c = true;
            b = double.Parse(textBox1.Text);
            d = "log";

        }

        private void button20_Click(object sender, EventArgs e)
        {
            c = true;
            b = double.Parse(textBox1.Text);
            d = "ln";

        }
    }
}

 

标签:c#,Text,void,object,private,textBox1,EventArgs,计算器,随笔
From: https://www.cnblogs.com/jiacheng-712/p/17779701.html

相关文章

  • CSP-S2023 游记
    S190pts。S2\(14:30\)全机房都打不开题,然后用U盘拷的题,乐。全机房补了\(20\operatorname{min}\)。\(14:50\)这是T1?这是T1?这是T1?这是T1?这是T1?一眼爆搜,\(10\operatorname{min}\)写完过了。\(15:00\)开T2。一眼感觉枚举\(r\),然后DS维护。推了一下感觉不好......
  • Github Actions实现Spring Boot自动化部署(第二弹)
    GithubActions实现SpringBoot自动化部署(第二弹)前言​ 今天就来讲述一下如何使用GitHub结合Actions实现SpringBoot程序从提交代码到打包、容器化、部署全过程自动化。首先咱们得现有一个能够在本地运行的SpringBoot程序,并且在Github上拥有一个仓库。一、自动化部署1.1提交......
  • CSP2023又寄
    推销丑死了的你谷博客\(\texttt{Day-?}\)初赛,轻轻松松寄掉,惊险S组踩线过。\(\texttt{Day-1}\)赛前动员,见到了老K/se敲了敲板子,然而屁用没有。\(\texttt{Day0}\)J组T1傻逼题,秒了数学题,打个暴力浅浅拿\(90\)分跑路。T2傻逼题,秒了。贪心,前缀最小值维护就行了。......
  • CSP 2023 游记
    省流:把#defineintlonglong写在快读下面,荣获全场最佳小丑奖。Day-1手速大赛很有趣,但有人不认识Aigony我不说是谁。Day0睡大觉,给小朋友讲考场注意事项。晚上试图向学妹传教vscode,但被反向传教了一顿code::blocks。怎么回事呢(做出一副努力学习的样子,但是我也很想玩......
  • P9752 [CSP-S 2023] 密码锁 题解
    分析最水S组T1。每次可以转动一个拨圈,或者转动相邻的两个拨圈,且幅度相同。那么就有一个简单粗暴的思路,枚举修改的方案,用vector来储存修改后的方案,存到map当中,当然也可以转换为数字存进去。切记要用两个map来储存,一个存方案,下文称为\(mp\),一个存这个方案在这个状态下......
  • 【ISCC2023线下】MISC1-帮帮小明writeup
    考点流量分析,TLS,二维码修复解题步骤首先速览一遍帮帮小明.pcapng,发现里面的协议有IMAP和TLS,这部分可能有线索打开统计->会话,TCP栏有两个终点为25端口的地址,追踪流量,是两次对话发现一个压缩包保存,发现有密码,里面是一个加密后的文件mosaic.bmp,用zipcenop排除了伪加密的可能......
  • 论文:Ultra Fast Deep Lane Detection with Hybrid Anchor Driven Ordinal Classificat
    论文名:UltraFastDeepLaneDetectionwithHybridAnchorDrivenOrdinalClassification混合Anchor驱动顺序分类的超快深车道检测研究问题:研究方法:主要结论:模型:问题:行文结构梳理:Abstrct:现有方法主要集中在(像素分割)+缺陷(复杂场景)+(通过观察)提出一种高效方......
  • CSP-S2023游?寄!
    赛前从学校坐校车去考点,发现qyb穿的衣服上面有个“璃月”,原来那次THUSC看到的是他啊,原批真可怕。老师搞错了解压密码,搞了二十分钟用u盘在每个人电脑上拷了一份题目,延时20min。t1开场一眼秒。简单题,枚举,依据题意判合法性即可。t2看了遍所有题后,感觉t2最简单。赛时前半小时推......
  • 在JavaScript中,如何检查空字符串、未定义或空值?
    内容来自DOChttps://q.houxu6.top/?s=在JavaScript中,如何检查空字符串、未定义或空值?JavaScript中是否有string.Empty,还是需要单独检查""?空字符串、未定义、空值等要检查一个真值:if(strValue){//strValue是一个非空字符串,true,42,Infinity,[],等等}要检查一个假......
  • 内核文档翻译(chatgpt) —— Pathname lookup (路径名查找)
    原文:https://www.kernel.org/doc/html/latest/filesystems/path-lookup.html内核中文件系统相关的文档汇总:FilesystemsintheLinuxkernelThiswrite-upisbasedonthreearticlespublishedatlwn.net:PathnamelookupinLinuxRCU-walk:fasterpathnamelookupinLi......