public Form1()
{
InitializeComponent();
textBox2.Text = "";//主显示屏
textBox1.Text = "";//顶端副显示屏
textBox3.Text = "";//中间变量,隐藏 } private void Form1_Load(object sender, EventArgs e)
{ }
//数字按键
private void button21_Click(object sender, EventArgs e)
{
if (sender is Button)
{
Button btn = sender as Button;
if (textBox2.Text == "")//如果主屏幕为0
{
textBox2.Text = btn.Text;//输入几就显示几
}
else
{
if (yunsuanfu)//上个按键是运算符
{
textBox2.Text = btn.Text;//主屏幕只显示本次输入的数字
yunsuanfu = false;
}
else
{
textBox2.Text += btn.Text;//上个按键不是运算符,主屏幕右侧累添上这个数字
}
}
}
} //加减乘除
private bool yunsuanfu = false;
private double jieguo1 = ;//点击加减乘除运算符显示的结果
private string text = "";
private void button26_Click(object sender, EventArgs e)
{
if (sender is Button)
{
Button btn = sender as Button;
text = btn.Text;
if(textBox3.Text=="")
{
textBox3.Text = btn.Text;
}
//判断上一步点击的是否是运算符
if (yunsuanfu==false)//不是运算符
{
textBox1.Text += textBox2.Text + text;
yunsuanfu = true;
if(textBox3.Text=="+")
{
jieguo1 += Convert.ToDouble(textBox2.Text);
textBox2.Text = jieguo1.ToString();
}
else if (textBox3.Text == "-")
{
jieguo1 -= Convert.ToDouble(textBox2.Text);
textBox2.Text = jieguo1.ToString();
}
else if (textBox3.Text == "*")
{
if (jieguo1 != )
{
jieguo1 = jieguo1 * Convert.ToDouble(textBox2.Text);
}
else
{
jieguo1 = Convert.ToDouble(textBox2.Text);
}
textBox2.Text = jieguo1.ToString();
}
else if (textBox3.Text == "/")
{
if (Convert.ToDouble(textBox2.Text) != )
{
if (jieguo1 != )
{
jieguo1 = jieguo1 / Convert.ToDouble(textBox2.Text);
}
else
{
jieguo1 = Convert.ToDouble(textBox2.Text); ;
}
textBox2.Text = jieguo1.ToString();
}
else
{
textBox2.Text = "除数不能为0";
}
} textBox3.Text = text;
}
else
{
if (textBox1.Text.Length > )
{
textBox1.Text = textBox1.Text.Substring(, textBox1.Text.Length - ) + text;
textBox3.Text = text;
}
else
{
textBox3.Text = text;
}
yunsuanfu = false;
}
}
} //小数点
private void button25_Click(object sender, EventArgs e)
{
//判断上一步点击的是否是运算符
if (yunsuanfu == false)//不是运算符
{
if (textBox2.Text.Contains(".") == false)
{
textBox2.Text = textBox2.Text + ".";
}
}
else
{
textBox2.Text = "0.";
yunsuanfu = false;
}
} //等号
private double jieguo = ;
private string text4 = "";
private string text5 = "";
private void button28_Click(object sender, EventArgs e)
{
jieguo = jieguo1;
jieguo1 = ;
text4 = textBox3.Text;
textBox3.Text = "";
text = "";
if (text4 == "")
{
text4 = button28.Text;
} textBox1.Clear();
textBox1.Text = "";
//判断上一步点击的是否是运算符
if (yunsuanfu == false)//不是运算符
{
yunsuanfu = true;
if (text4 == "+")
{
jieguo += Convert.ToDouble(textBox2.Text);
textBox2.Text = jieguo.ToString();
}
else if (text4 == "-")
{
jieguo -= Convert.ToDouble(textBox2.Text);
textBox2.Text = jieguo.ToString();
}
else if (text4 == "*")
{
if (jieguo != )
{
jieguo = jieguo * Convert.ToDouble(textBox2.Text);
}
else
{
jieguo = Convert.ToDouble(textBox2.Text);
}
textBox2.Text = jieguo.ToString();
}
else if (text4 == "/")
{
if (textBox2.Text != "")
{
if (jieguo != )
{
jieguo = jieguo / Convert.ToDouble(textBox2.Text);
}
else
{
jieguo = Convert.ToDouble(textBox2.Text); ;
}
textBox2.Text = jieguo.ToString();
}
else
{
textBox2.Text = "除数不能为0";
}
}
else if (text4 == "=")
{
jieguo = jieguo;
} text5 = text4;
text4 = button28.Text;
}
else
{
yunsuanfu = false;
double jishu = ;
if (text4 == "+")
{
jishu = jieguo;
jieguo += jishu; textBox2.Text = jieguo.ToString();
}
else if (text4 == "-")
{
jishu = jieguo;
jieguo -=jishu; textBox2.Text = jieguo.ToString();
}
else if (text4 == "*")
{
jishu = jieguo;
jieguo=jieguo*jishu; textBox2.Text = jieguo.ToString();
}
else if (text4 == "/")
{
if (jieguo != )
{
jishu = jieguo;
jieguo = jieguo / jishu; textBox2.Text = jieguo.ToString();
}
else
{
textBox2.Text = "除数不能为0";
}
}
else if (text4 == "=")
{
jishu =Convert.ToDouble(textBox1.Text);
if (text5 == "+")
{
jieguo+=jishu ;
}
else if (text5 == "-")
{
jieguo-=jishu;
}
else if (text5 == "*")
{
jieguo *=jishu;
}
else if (text5 == "/")
{
if (jishu != )
{
jieguo /= jishu;
}
else
{
textBox2.Text = "除数不能为0";
}
}
}
}
yunsuanfu = false; }
//按键C
private void button8_Click(object sender, EventArgs e)
{
textBox2.Clear();
textBox1.Clear();
textBox3.Clear();
textBox2.Text = "";
textBox1.Text = "";
textBox3.Text = "";
jieguo = ;
jieguo1 = ;
yunsuanfu = false;
text = "";
text4 = "";
text5 = "";
}
//CE键
private void button7_Click(object sender, EventArgs e)
{ textBox2.Clear();
textBox2.Text = "";
}
//退格键
private void button6_Click(object sender, EventArgs e)
{
if (textBox2.Text.Length > )
{
textBox2.Text = textBox2.Text.Substring(, textBox2.Text.Length - );
}
else if (textBox2.Text.Length == )
{
textBox2.Text = textBox2.Text.Substring(, textBox2.Text.Length - );
textBox2.Text = "";
}
else
{
textBox2.Text = "";
}
}
//主屏幕字体随个数变化而变化
private void textBox2_TextChanged(object sender, EventArgs e)
{
if (textBox2.Text.Length < )
{
this.textBox2.Font = new System.Drawing.Font("宋体", 21.75f);
}
if (textBox2.Text.Length > )
{
this.textBox2.Font = new System.Drawing.Font("宋体", 15f);
}
if (textBox2.Text.Length > )
{
this.textBox2.Font = new System.Drawing.Font("宋体", 13f);
}
if (textBox2.Text.Length > )
{
this.textBox2.Font = new System.Drawing.Font("宋体", 11f);
}
}

winform制作简单计算器的更多相关文章

  1. 1.C#WinForm基础制作简单计算器

    利用c#语言编写简单计算器: 核心知识点: MessageBox.Show(Convert.ToString(comboBox1.SelectedIndex));//下拉序号 MessageBox.S ...

  2. 《自制编程语言》笔记:使用yacc与lex制作简单计算器

    1.代码 1.1)test.l 1.2)test.y 1.3)Makefile (因为是在linux环境下,所以使用了Makefile) 2.编译与运行 2.1)编译 2.2)运行 1.代码(也可以在 ...

  3. 用JavaScript制作简单的计算器

    <html > <head> <title>简单计算器</title> <style type="text/css"> ...

  4. 基于MFC的一个简单计算器

    写一个简单的计算器并不是什么很难的事,主要目的是要通过这个程序来学习和分析其中的核心算法.这个简易计算器的核心部分就是对输入的表达式的正确性判断与求值,其中包括对表达式的解析.中缀表达式转后缀表达式. ...

  5. C# Winform制作虚拟键盘,支持中文

    原文:C# Winform制作虚拟键盘,支持中文           最近在做一个虚拟键盘功能,代替鼠标键盘操作,效果如下:        实现思路:          1  构建中文-拼音 数据库, ...

  6. C# WinForm制作电子琴键盘

    上一篇 http://hovertree.com/h/bjaf/y8qol2p4.htm 再上一篇的基础上,使用WinForm制作了一个电子琴键盘: 演示地址 http://hovertree.com ...

  7. Highcharts使用教程(1):制作简单图表

    今天我们要使用JavaScript图表Highcharts制作简单的柱形图,我们已经安装好Highcharts,让我们开始制作图表吧. 步骤一 在网页中添加一个div.设置id,设置图表长.高.代码如 ...

  8. 菜鸟学Android编程——简单计算器《一》

    菜鸟瞎搞,高手莫进 本人菜鸟一枚,最近在学Android编程,网上看了一些视频教程,于是想着平时手机上的计算器应该很简单,自己何不尝试着做一个呢? 于是就冒冒失失的开撸了. 简单计算器嘛,功能当然很少 ...

  9. ZAM 3D 制作简单的3D字幕 流程(二)

    原地址:http://www.cnblogs.com/yk250/p/5663907.html 文中表述仅为本人理解,若有偏差和错误请指正! 接着 ZAM 3D 制作简单的3D字幕 流程(一) .本篇 ...

随机推荐

  1. ZLL主机接口的信息处理流程

    主机接口的信息处理流程 在我们翻译的文档中是用电脑端来模拟主机的,电脑代替网关发送主机接口命令的环节是在zll_controller.c中实现的,(在下载的文件中已经提供了其对应的可执行文件zllCm ...

  2. UED

    User Experience Design(用户体验设计),简称UED.UED是进行产品策划的主力之一,他们用自己的知识.经验.设计能力拿出设计方案. UED不只是互联网专家,还是行业专家.能够用自 ...

  3. css把超出的部分显示为省略号的方法兼容火狐

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...

  4. 导出word使用模版

    在我们做我们的小组项目的时候,刚开始的时候我们用到的是Mvc+EF,用上了我们的ITOO框架.在最开始的计划,我们要用到瑞郎报表.可是呢,由于工期原因以及技术暂时没有实现,我们不得不想一个比较折中的方 ...

  5. codeforces733-C. Epidemic in Monstropolis 贪心加链表

    题意 现在有一个怪兽序列a[i],权值大的怪兽可以吃权值小的怪兽,吃完之后权值大的怪兽的权值会变成两者权值的和,相邻的怪兽才能吃 吃完之后,位置合并,队列前移,从左到右重新编号,重复这一过程, 然后给 ...

  6. [导入]Eclipse 导入/编译 Hadoop 源码

    http://www.cnblogs.com/errorx/p/3779578.html 1.准备工作 jdk: eclipse: Maven: libprotoc :https://develope ...

  7. C# 静态方法和非静态方法

    转载:http://www.cnblogs.com/mikelij/archive/2010/08/13/1798578.html 本文将围绕c#静态方法和实例方法讨论一下.针对一些观点,如:&quo ...

  8. 廖雪峰js教程笔记5 Arrow Function(箭头函数)

    为什么叫Arrow Function?因为它的定义用的就是一个箭头: x => x * x 上面的箭头函数相当于: function (x) { return x * x; } 箭头函数 阅读: ...

  9. jq ajax遇到的错误集合

    一.错误: Uncaught InvalidStateError: Failed to read the 'selectionDirection' property from 'HTMLInputEl ...

  10. ssl原理,非对称加密握手,对称加密传输

    SSL的基本思想是用非对称加密来建立链接(握手阶段),用对称加密来传输数据(传输阶段).这样既保证了密钥分发的安全,也保证了通信的效率. SSL握手,单方服务器认证(一般的浏览器上网) SSL握手,双 ...