C#编写一个计算器
编写一个计算器,练习在窗体上添加控件、调整控件的布局,设置或修改控件属性,编写事件处理程序的方法。
代码:
- 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 Lab07_1
- {
- 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 textBox1_TextChanged(object sender, EventArgs e)
- {
- }
- private void button5_Click(object sender, EventArgs e)
- {
- if (c == true)
- {
- textBox1.Text = "";
- c = false;
- }
- textBox1.Text += "5";
- }
- private void button13_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 button10_Click(object sender, EventArgs e)
- {
- c = true;
- b = double.Parse(textBox1.Text);
- d = "-";
- }
- private void 雨轩计算机_Load(object sender, EventArgs e)
- {
- }
- private void button2_Click(object sender, EventArgs e)
- {
- if (c == true)
- {
- textBox1.Text = "";
- c = false;
- }
- textBox1.Text += "2";
- }
- 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 button4_Click(object sender, EventArgs e)
- {
- if (c == true)
- {
- textBox1.Text = "";
- c = false;
- }
- textBox1.Text += "4";
- }
- private void button6_Click(object sender, EventArgs e)
- {
- if (c == true)
- {
- textBox1.Text = "";
- c = false;
- }
- textBox1.Text += "6";
- }
- private void button3_Click(object sender, EventArgs e)
- {
- if (c == true)
- {
- textBox1.Text = "";
- c = false;
- }
- textBox1.Text += "3";
- }
- private void button14_Click(object sender, EventArgs e)
- {
- textBox1.Text = "";
- }
- private void button15_Click(object sender, EventArgs e)
- {
- c = true;
- b = double.Parse(textBox1.Text);
- d = "+";
- }
- 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 button16_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 "平方": a = b * b; break;
- case "开方": a =Math.Sqrt(b); break;
- case "log": a = Math.Log10(b); break;
- case "ln": a = Math.Log(b); break;
- }
- textBox1.Text = a + "";
- c = true;
- }
- private void button20_Click(object sender, EventArgs e)
- {
- if (textBox1.Text == "") { MessageBox.Show("请先输入值再计算!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); }
- else
- {
- c = true;
- b = double.Parse(textBox1.Text);
- d = "ln";
- }
- }
- private void button17_Click(object sender, EventArgs e)
- {
- if (textBox1.Text == "") { MessageBox.Show("请先输入值再计算!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); }
- else
- {
- c = true;
- b = double.Parse(textBox1.Text);
- d = "平方";
- }
- }
- private void button18_Click(object sender, EventArgs e)
- {
- if (textBox1.Text == "") { MessageBox.Show("请先输入值再计算!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); }
- else
- {
- c = true;
- b = double.Parse(textBox1.Text);
- d = "开方";
- }
- }
- private void button19_Click(object sender, EventArgs e)
- {
- if (textBox1.Text == "") { MessageBox.Show("请先输入值再计算!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); }
- else
- {
- c = true;
- b = double.Parse(textBox1.Text);
- d = "log";
- }
- }
- }
- }
界面演示:
C#编写一个计算器的更多相关文章
- 用python编写一个计算器
# 1 - 2 * ((60-30 +(-40.0/5) * (9-2*5/3 + 7 /3*99/4*2998 +10 * 568/14 )) - (-4*3)/ (16-3*2)))# 通过Pyt ...
- [javascript] 编写一个计算器,实现加减法
1.代码 <script> function sum(){ //加法 var value1 = document.getElementById("num1").valu ...
- python 正则的使用 —— 编写一个简易的计算器
在 Alex 的博客上看到的对正则这一章节作业是编写一个计算器,要求能计算出下面的算式. 1 - 2 * ( (60-30 +(-40/5) * (9-2*5/3 + 7 /3*99/4*2998 + ...
- 编写一个通用的Makefile文件
1.1在这之前,我们需要了解程序的编译过程 a.预处理:检查语法错误,展开宏,包含头文件等 b.编译:*.c-->*.S c.汇编:*.S-->*.o d.链接:.o +库文件=*.exe ...
- CSharpGL(34)以从零编写一个KleinBottle渲染器为例学习如何使用CSharpGL
CSharpGL(34)以从零编写一个KleinBottle渲染器为例学习如何使用CSharpGL +BIT祝威+悄悄在此留下版了个权的信息说: 开始 本文用step by step的方式,讲述如何使 ...
- .NET Core RC2发布在即,我们试着用记事本编写一个ASP.NET Core RC2 MVC程序
在.NET Core 1.0.0 RC2即将正式发布之际,我也应应景,针对RC2 Preview版本编写一个史上最简单的MVC应用.由于VS 2015目前尚不支持,VS Code的智能感知尚欠火候,所 ...
- 网络爬虫:使用Scrapy框架编写一个抓取书籍信息的爬虫服务
上周学习了BeautifulSoup的基础知识并用它完成了一个网络爬虫( 使用Beautiful Soup编写一个爬虫 系列随笔汇总 ), BeautifulSoup是一个非常流行的Python网 ...
- 作业二:个人编程项目——编写一个能自动生成小学四则运算题目的程序
1. 编写一个能自动生成小学四则运算题目的程序.(10分) 基本要求: 除了整数以外,还能支持真分数的四则运算. 对实现的功能进行描述,并且对实现结果要求截图. 本题发一篇随笔,内容包括: 题 ...
- 用Java语言编写一个简易画板
讲了三篇概博客的概念,今天,我们来一点实际的东西.我们来探讨一下如何用Java语言,编写一块简易的画图板. 一.需求分析 无论我们使用什么语言,去编写一个什么样的项目,我们的第一步,总是去分析这个项目 ...
随机推荐
- java中如何将嵌套循环性能提高500倍
java中如何将嵌套循环性能提高500倍 转载请注明出处https://www.cnblogs.com/funnyzpc/p/15975882.html 前面 似乎上一次更新在遥远的九月份,按照既定的 ...
- linux作业--第四周
1.自建yum仓库,分别为网络源和本地源 所有Yum仓库的配置文件均需以 .repo 结尾并存放在/etc/yum.repos.d/目录中的 [base] : yum仓库唯一标识符,避免与其它仓库冲突 ...
- Actor model 的理解与 protoactor-go 的分析
Overview Definition From wikipedia The actor model in computer science is a mathematical model of co ...
- LGP4463题解
这玩意儿怎么看上去就很经典啊( 哦互不相同啊,那没事了( 考虑一个 \(\rm DP\).由于限制了互不相同,那么我们考虑从值域开始想. 设 \(dp_{n,k}\) 为在 \([1,n]\) 中选了 ...
- CTS,CLS,CLR
1)CTS通用类型系统(Common Type System) CTS不但实现了COM的变量兼容类型,而且还定义了通过用户自定义类型的方式来进行类型扩展.任何以.NET平台作为目标的语言必须建立它的数 ...
- Hive框架
1.什么是Hive? Hive 是基于Hadoop之上的数据仓库.2.什么是数据仓库? 数据仓库其实就是一个数据库 数据仓库是一个面向主题的,集成的,不可更新的,随时间不变化的数据集合,它用于支持 企 ...
- Play商店显示需要进行身份认证。您需要登录自己的Google帐户
前段时间把一加6系统从H2OS换到OxygenOS,Play商店死活不能登录,网络配置等问题已经排除,重装Google全家桶也没有解决问题,最后找到原因. 解决办法:在应用列表中找到Google Pl ...
- kubernetes关于证书配置得问题总结
总结证书配置 1.证书首先分为两种配置方式, 1) 一种是在集群中配置 2) 一种是在上游负载均衡中配置. 1)https证书在集群中配置,并域名直接解析到集群的ingress-nginx-contr ...
- C语言知识点的实例
编译环境:Visual Studio 2012 编程语言:C @ 目录 1.memcpy与'/0' 2.volatile的使用 3.数字转字符 4.memcpy len 与指针加减 len 的区别 5 ...
- 端口转发工具--lcx
简介 lcx是一款强大的内网端口转发工具,用于将内网主机开放的内部端口映射到外网主机(有公网IP)任意端口.它是一款命令行工具,当然也可以在有权限的webshell下执行,正因如此lcx常被认为是一款 ...