使用C#创建一个计算器
2017-09-04 10:41
429 查看
本文是当初涉猎C#时写的一个小程序,现在已经没有使用这个语言了。不过想说的是:C#确实我见过的最优雅的语言(也许我见过的语言还少,可能还有比她更优雅的语言吧) 。我曾经做过一点Excel和AutoCAD的简单二次开发,使用C#比C++简洁、高效多了。现在就说下这个计算器的设计吧,我还是直接贴代码吧,简洁。
1、首先创建一个大窗体,然后放置各个空间和文本框。创建的界面如下:
2、编写控件触发函数
1、首先创建一个大窗体,然后放置各个空间和文本框。创建的界面如下:
2、编写控件触发函数
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 { string Operation; public Form1() { InitializeComponent(); } private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { } private void textBox1_TextChanged(object sender, EventArgs e) { } private void button7_Click(object sender, EventArgs e) { textBox1.Text = textBox1.Text+button7.Text; } private void button8_Click(object sender, EventArgs e) { textBox1.Text = textBox1.Text+button8.Text; } private void button9_Click(object sender, EventArgs e) { textBox1.Text = textBox1.Text + button9.Text; } private void button10_Click(object sender, EventArgs e) { textBox1.Text = textBox1.Text + button10.Text; } private void button11_Click(object sender, EventArgs e) { textBox1.Text = textBox1.Text + button11.Text; } private void button12_Click(object sender, EventArgs e) { textBox1.Text = textBox1.Text + button12.Text; } private void button13_Click(object sender, EventArgs e) { textBox1.Text = textBox1.Text + button13.Text; } private void button14_Click(object sender, EventArgs e) { textBox1.Text = textBox1.Text + button14.Text; } private void button15_Click(object sender, EventArgs e) { textBox1.Text = textBox1.Text + button15.Text; } private void button16_Click(object sender, EventArgs e) { textBox1.Text = textBox1.Text + button16.Text; } private void button1_Click(object sender, EventArgs e) { string str; str= button1.Text; textBox1.Text = textBox1.Text + str; Operation = str; } private void button2_Click(object sender, EventArgs e) { string str; str = button2.Text; textBox1.Text = textBox1.Text + str; Operation = str; } private void button3_Click(object sender, EventArgs e) { string str; str = button3.Text; textBox1.Text = textBox1.Text + str; Operation = str; } private void button4 4000 _Click(object sender, EventArgs e) { string str; str = button4.Text; textBox1.Text = textBox1.Text + str; Operation = str; } private void button5_Click(object sender, EventArgs e) { string str; str = button5.Text; string tempStr = textBox1.Text; textBox1.Text = textBox1.Text + str; string signal; signal = Operation; string numStr1,numStr2; string[] StrArray = tempStr.Split(char.Parse(signal)); numStr1 = StrArray[0]; numStr2 = StrArray[1]; double num1, num2,result; num1 = double.Parse(numStr1); num2 = double.Parse(numStr2); switch(signal) { case "+": result=num1+num2; textBox1.Text = textBox1.Text + result.ToString(); break; case "-": result=num1-num2; textBox1.Text = textBox1.Text + result.ToString(); break; case "*": result=num1*num2; textBox1.Text = textBox1.Text + result.ToString(); break; case "/": result=num1/num2; textBox1.Text = textBox1.Text + result.ToString(); break; } } private void button6_Click(object sender, EventArgs e) { textBox1.Text = ""; } private void label1_Click(object sender, EventArgs e) { } private void label2_Click(object sender, EventArgs e) { } } }上面的完整工程我放在这个地方了,网址:http://download.csdn.net/download/lingyunxianhe/9963006
相关文章推荐
- 如何使用C#创建一个三层的数据库应用程序
- 在C#中使用Ribbon界面(一)——创建一个Ribbon窗口
- 使用c# 5分钟 创建一个Roguelike 游戏
- C#第2次试验(1).创建一个抽象类A,该类中包含一个求两个数之和抽象方法。创建一个子类B,在B中重写求和方法,且使用方法重载使得方法可以分别计算整数、双精度、字符串。
- 使用C#创建一个简单的Windows服务
- 使用C#创建一个简单的Windows服务
- 使用C#创建一个安装向导
- C#创建服务及使用程序自动安装服务,.NET创建一个即是可执行程序又是Windows服务的exe(转)
- 如何使用C#创建一个三层的数据库应用程序
- C#创建服务及使用程序自动安装服务,.NET创建一个即是可执行程序又是Windows服务的exe
- C#创建服务及使用程序自动安装服务,.NET创建一个即是可执行程序又是Windows服务的exe
- 使用c#创建一个可以监视全局鼠标位置的程序
- [转]C#创建服务及使用程序自动安装服务,.NET创建一个即是可执行程序又是Windows服务的exe
- 使用c#创建一个可以监视全局鼠标位置的程序
- 常量,字段,构造方法 调试 ms 源代码 一个C#二维码图片识别的Demo 近期ASP.NET问题汇总及对应的解决办法 c# chart控件柱状图,改变柱子宽度 使用C#创建Windows服务 C#服务端判断客户端socket是否已断开的方法 线程 线程池 Task .NET 单元测试的利剑——模拟框架Moq
- 如何使用C#创建一个三层的数据库应用程序
- 使用ASP.NET MVC(C#)15分钟内创建一个电影数据库程序
- 如何使用C# WEBSERVICE 创建一个三层的数据库应用程序 http://www.xxju.net/article/200412/29_0004326567.htm
- 使用C#编写一个计算器(OK)
- 使用C#创建一个进程杀手Windows服务