使用C#创建一个计算器
来源:互联网 发布:java 两个list 去重 编辑:程序博客网 时间:2024/06/01 10:04
本文是当初涉猎C#时写的一个小程序,现在已经没有使用这个语言了。不过想说的是:C#确实我见过的最优雅的语言(也许我见过的语言还少,可能还有比她更优雅的语言吧) 。我曾经做过一点Excel和AutoCAD的简单二次开发,使用C#比C++简洁、高效多了。现在就说下这个计算器的设计吧,我还是直接贴代码吧,简洁。
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_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
阅读全文
1 0
- 使用C#创建一个计算器
- 使用Java 创建一个计算器
- 创建一个计算器
- 创建一个简单的计算器
- 创建一个图形界面的计算器
- c#启动一个计算器进程
- 记录一个c#计算器程序
- lex yacc 创建一个桌面计算器
- Html+JS创建一个简单的计算器
- 使用 HTML 、JavaScript 创建一个简单的计算器,包含加、减、乘、除四个功能
- 一个基于c# GUI的计算器
- C#实现的一个小小计算器
- 用C# winform 编写一个计算器
- web中用c#设计一个简易计算器
- 使用c#开方计算器(1设计思路)
- 使用C#模拟简易的计算器
- 如何使用C#创建一个三层的数据库应用程序
- 如何使用C#创建一个三层的数据库应用程序
- Selenium怎样驱动Firefox浏览器
- [RK3288][Android6.0] 调试笔记 --- 开机视频无法播放
- 分享一款mac思维导图软件omniGraffle(破解版)
- python基础-变量
- 涂鸦移动一面
- 使用C#创建一个计算器
- Android学习笔记四十三之Shape详解
- log4j源码解析
- web过滤器与监听器
- android按键绑定监听器三种方式
- spring 配置注意事项
- Integer Sequences SGU
- Dynamic Coattention Networks For Question Answering
- web设计器--设计流程图(raphael)源码myflow.js(三)