C#简单计算器_第1页
C#简单计算器_第2页
C#简单计算器_第3页
C#简单计算器_第4页
C#简单计算器_第5页
已阅读5页,还剩9页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、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 简单计算器Form(public partial class Forml :public Forml ()InitializeComponent();key = 0;firstNumber = 0;lastNumber

2、 = 0; / 初始化private double firstNumber; / 保存第个数值private double lastNumber; / 保存第二个数值int key; /操作符标记。1为+, 2为-,3为*,4为/private void buttonl0_Click( objectEventArgs e) /Isender,textBox1. Text +=1private void button9_Click( objectEventArgs e) /2sender,textBox1. Text +=private void buttonll_Click( objectEv

3、entArgs e) /3sender,textBox1. Text +=;private void button5_Click( objectsender,EventArgs e) /4textBox1.Text +=private voidbutton2_Click( object sender,EventArgs e) /5textBox1. Text 丄5;private void button8_Click(object sender,EventArgs e) /66textBox1.Text+= private voidbuttonl_Click( object sender,Ev

4、entArgs e) /77.textBox1. Text +=?private void button7_Click( object sender,EventArgs e) /8 textBox1.Text += 8private void button3_Click( object sender,EventArgs e) /9 textBox1. Text += 9 ;private void buttonl4_Click( object sender,EventArgs e) /0if (textBoxl. Text. StartsWith( 0 ) &text Box 1. Tex t

5、 Length = 1)return : /角军决000000问题textBox1.Text += 0 ;private void buttonl3_Click( object sender,Eve nt Args e) /text Box 1. Tex t Cont ains ( “ )/C#中Contains 一般是验证对象是否包含指定的子对象/ 根.据 list. Contains (/z,/z)案!J断.list 可 能是一个 string 或者 ArrayList./验证list里面是否包含了一个,字符串. return;/解决.开头,且不能出现多个.的问题textBox1. Tex

6、t +=;private void buttonl5_Click( object sender,EventArgs e) /+if (textBox1.Text 二二 ) return ;firstNumber =Convert ToDouble (textBox1.Text); / 彳各 textBox1.Text转换为doubletextBox 1. TextHH=key = 1;private void buttonl2_Click( objectEventArgs e) /-if (textBoxl. Text =” )return ;firstNumber =Convert ToDo

7、uble (textBox1. Text); textBox1. Text 二 key二 2;priva.te void button6_Click( objectEventArgs e) /*(if (textBox1. Text 二二“)returnsendersenderfirstNumberConvert ToDouble (textbox1.Text);textBox1.Text 二 key = 曲3;)private void button4_Click( objectEve nt Args e) /,/,if (textBoxl. Text =” ) return ;firstN

8、umber =Convert ToDouble (textBox1.Text);textBox1.Text 二 key = 4;private void buttonl6_Click( objectEventArgs e) / =if (textBox1. Text = “ ) return :sender,sender,lastNumber =Convert . ToDouble(textBoxl. Text) ; /convert 函数 用来 转换数据类型switch (key)case 1: textBox1. Text 二(fiistNumber + lastNumber) ToStr

9、ing();break ;case 2: textBox1.Text 二 (firstNumber-lastNumber)ToString(); break ;case 3: textBox1.Text 二 (firstNumber* lastNumber)ToString(); break ;case 4:if (lastNumber = 0) MessageBox. Show(除数不能 为0,提示);/textBoxl. Text =除数不 能为0;return :else/ lastNumber)ToString(); breakdefauIt : return ;private void buttonl8_Click( object sender, EventArgs e) / CtextBox1. Text 二;private void buttonl7_Click( object sender, Event

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论