CWP7简单计算器_第1页
CWP7简单计算器_第2页
CWP7简单计算器_第3页
已阅读5页,还剩46页未读 继续免费阅读

下载本文档

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

文档简介

1、基于 C#窗体程序的一个简单计算器,进制转换的小数部分没有完善,初学者,继续努力中.各位大侠请指教,各位小白大家互相学习,一起进步using System;using System.Collections.Generic;using SystemponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Threading;namespace js_easypublicpartialclassForm1

2、 :FormstringFh ="" ; / 定义符号位double a, b, c;/ 定义 a第一个值, b第二个值, c输出值long s = 1;/ 定义小数最初为一位publicForm1()InitializeComponent();publicvoid anniu(double i)/ 按钮方法if(Fh.Equals("" ) / 是否当前有运算符第 1页if(s = 1)/ 判断是否有小数点a = a * 10 + i;/ 计算无小数的值elsea = a + i / s;/ 计算有小数的值s = s * 10;/ 计算下一个小数的位置

3、textBox1.Text = a.ToString();/ 显示计算的结果else/ 当前有运算符的方法if(!(c = 0) b = 0; c = 0; / 当有计算结果就清除 B的值if(s = 1)/ 判断是否有小数点b = b * 10 + i;/ 计算无小数的值elseif(i = 0)/ 判断在小数位后添加0s = s * 10;/ 计算下一个小数的位置elseb = b + i / s;/ 计算有小数的值s = s * 10;/ 计算下一个小数的位置textBox1.Text = b.ToString();/ 显示计算的结果publicvoid js()/ 数学计算的方法if(

4、Fh ="/" ) / 判断是否除数等于0if(b = 0)/ 是则不计算第 2页textBox1.Text ="0" ; / 被除数不能为 0return ; / 返回elsec = a / b;else /如果不是出发计算则执行其他计算if(Fh.Equals("+" ) c = a + b; if(Fh.Equals("-" ) c = a - b; if(Fh.Equals("*" ) c = a * b; if(Fh.Equals("%") c = a % b; t

5、extBox1.Text = c.ToString();/ 显示计算结果a = c;/ 将结果给第一个变量作为publicvoid fh(stringstr)/ 接收运算符的方法if(Fh.Equals("" ) / 当前是否已经有运算符Fh = str; s = 1;/ 没有则接收运算符, 小数点失效elsejs();s = 1; Fh = str;/ 有则计算当前的值, 小数点失效/* 暂不支持小数进制转换*/publicvoid jz2(stringjg)/2 进制转换long temp =Convert .ToInt64(jg);if(temp < 2)tex

6、tBox2.Text = temp.ToString();第 3页elseinti = 0;int array =new int 1000;while (temp > 0)arrayi+ = (int )temp % 2;temp /= 2;int array_1 =new int i;for( intj = i - 1; j >= 0; j-)array_1j = arrayi - 1 - j;/Array.Reverse(array_1);foreach( intkin array_1)textBox2.Text += k.ToString();publicvoid jz8(s

7、tringjg)/8 进制转换long temp =Convert .ToInt64(jg);if(temp < 9)textBox2.Text = temp.ToString();elseinti = 0;int array =new int 1000;while (temp > 0)arrayi+ = (int )temp % 8;temp /= 8;第 4页int array_1 =new int i;for( intj = i - 1; j >= 0; j-)array_1j = arrayi - 1 - j;/Array.Reverse(array_1);forea

8、ch( intkin array_1)textBox2.Text += k.ToString();publicvoid jz16(stringjg)/ 十六进制转换long temp =Convert .ToInt64(jg);if(temp < 16)textBox2.Text = temp.ToString();elseinti = 0;int array =new int 1000;/ 浪费空间,节省时间while (temp > 0)arrayi+ = (int )temp % 16;temp /= 16;int array_1 =new int i;for( intj =

9、 i - 1; j >= 0; j-)array_1j = arrayi - 1 - j;foreach( intkin array_1)textBox2.Text += k.ToString("X" );第 5页publiclong Jiec(long jg)/ 阶乘long temp = jg;if(temp = 1)return1;elselong temp1 = Jiec(temp-1);temp = temp * temp1;returntemp;privatevoid Form1_Load( objectsender,EventArgs e)textBox

10、1.Font =new Font ( " 宋体 " , 14,FontStyle.Bold);textBox2.Font =new Font ( " 宋体 " , 14,FontStyle.Bold);this .Text =" 简单计算器 " ;stringdir ="imageangry.jpg"pictureBox1.Image =Image.FromFile(dir);pictureBox1.SizeMode=PictureBoxSizeMode .StretchImage;pictureBox1.Dock

11、 =DockStyle .Fill;button1.Text ="=" ;button2.Text ="2" ;button3.Text ="3" ;button4.Text ="4" ;button5.Text ="5" ;第 6页button6.Text ="C1" ;button7.Text ="7" ;button8.Text ="8" ;button9.Text ="9" ;button10.Text =&

12、quot;0" ;button12.Text ="+" ;button13.Text ="-"button14.Text ="*"button15.Text ="%"button16.Text ="/"button17.Text ="6" ;button18.Text ="."button19.Text ="1" ;button11.Text ="C2" ;button20.Text ="Sin&

13、quot;button21.Text ="Cos" ;button22.Text ="Tan" ;button23.Text ="Log10" ;button24.Text="Lg" ;button25.Text ="!"button25.Font =new Font ( "" ,10, FontStyle .Bold);button26.Text ="2"第 7页radioButton1.Text ="二进制 "radioButton

14、2.Text ="八进制 "radioButton3.Text ="十六进制 "radioButton4.Text =" 十进 制"privatevoidtextBox1_TextChanged(objectsender,EventArgs e)textBox1.BackColor =Color .White;textBox1.Enabled =false;privatevoidtextBox2_TextChanged(objectsender,EventArgs e)textBox1.BackColor =Color .White;

15、textBox1.Enabled =false;privatevoid button19_Click(object sender, EventArgs e)anniu(1);privatevoidbutton2_Click(objectsender,EventArgse)anniu(2);privatevoidbutton3_Click(objectsender,EventArgse)anniu(3);privatevoidbutton4_Click(objectsender,EventArgse)anniu(4);privatevoidbutton5_Click(objectsender,E

16、ventArgse)anniu(5);第 8页privatevoidbutton17_Click(objectsender,EventArgse)anniu(6);privatevoidbutton7_Click(objectsender,EventArgse)anniu(7);privatevoidbutton8_Click(objectsender,EventArgse)anniu(8);privatevoidbutton9_Click(objectsender,EventArgse)anniu(9);privatevoidbutton10_Click(objectsender,Event

17、Argse)if(!textBox1.Text.Equals("0" )anniu(0);privatevoidbutton18_Click(objectsender,EventArgse)if(s = 1) s = 10; privatevoidbutton14_Click(objectsender,EventArgse)fh("*" );button14.BackColor =Color .BlueViolet;privatevoidbutton15_Click(objectsender,EventArgse)fh("%");bu

18、tton15.BackColor =Color .BlueViolet;privatevoidbutton12_Click(objectsender,EventArgse)fh("+" );button12.BackColor =Color .BlueViolet;第 9页privatevoidbutton13_Click(objectsender,EventArgse)fh("-" );button13.BackColor =Color .BlueViolet;privatevoidbutton16_Click(objectsender,EventAr

19、gse)fh("/" );button16.BackColor =Color .BlueViolet;privatevoidbutton6_Click(objectsender,EventArgse)textBox1.Text ="0" ; / 清空 TEXTBOX的显示值a = 0; b = 0; c = 0; s = 1; Fh ="" ;/初始化所有值privatevoidbutton1_Click(objectsender,EventArgse)fh("=" );Thread .Sleep(300); /颜

20、色改变延迟button12.BackColor =SystemColors .Control; /还原按钮颜色button13.BackColor =SystemColors .Control;button14.BackColor =SystemColors .Control;button15.BackColor =SystemColors .Control;button16.BackColor =SystemColors .Control;privatevoidradioButton1_CheckedChanged(objectsender,EventArgs e)if(textBox2.T

21、ext !=null )textBox2.Text ="" ;第10 页jz2(textBox1.Text);elsejz2(textBox1.Text);privatevoidradioButton2_CheckedChanged(objectsender,EventArgs e)if(textBox2.Text !=null )textBox2.Text ="" ;jz8(textBox1.Text);elsejz8(textBox1.Text);privatevoidradioButton3_CheckedChanged(objectsender,

22、EventArgs e)if(textBox2.Text !=null )textBox2.Text ="" ;jz16(textBox1.Text);elsejz16(textBox1.Text);privatevoid button11_Click(objectsender,EventArgs e)textBox2.Text ="" ;privatevoidradioButton4_CheckedChanged(objectsender,EventArgs e)textBox2.Text = c.ToString();第11 页privatevoid

23、 button20_Click(objectsender,EventArgse)double temp =Convert .ToDouble(textBox1.Text);temp =Math.Sin(3.1415926 * temp / 180);if(textBox2.Text !=null)textBox2.Text ="" ;textBox2.Text = temp.ToString();elsetextBox2.Text = temp.ToString();privatevoid button21_Click(objectsender,EventArgse)dou

24、ble temp =Convert .ToDouble(textBox1.Text);temp =Math.Cos(3.1415926*temp/180);if(textBox2.Text !=null)textBox2.Text ="" ;textBox2.Text = temp.ToString();elsetextBox2.Text = temp.ToString();privatevoid button22_Click(objectsender,EventArgse)double temp =Convert .ToDouble(textBox1.Text);temp

25、 =Math.Tan(3.1415926*temp/180);if(textBox2.Text !=null)textBox2.Text ="" ;textBox2.Text = temp.ToString();第12 页elsetextBox2.Text = temp.ToString();privatevoid button23_Click(objectsender,EventArgs e)double temp =Convert .ToDouble(textBox1.Text);temp =Math.Log10(temp) ;if(textBox2.Text !=nu

26、ll )textBox2.Text ="" ;textBox2.Text = temp.ToString();elsetextBox2.Text = temp.ToString();privatevoid button24_Click(objectsender,EventArgs e)double temp =Convert .ToDouble(textBox1.Text);temp =Math.Log(temp);if(textBox2.Text !=null )textBox2.Text ="" ;textBox2.Text = temp.ToStr

27、ing();elsetextBox2.Text = temp.ToString();privatevoid button25_Click(objectsender,EventArgs e)long temp =Convert .ToInt64(textBox1.Text);Jiec(temp);if(textBox2.Text !=null )第13 页textBox2.Text ="" ;textBox2.Text = Jiec(temp).ToString();elsetextBox2.Text = Jiec(temp).ToString();privatevoid b

28、utton26_Click(objectsender,EventArgs e)long y =Convert .ToInt64(textBox1.Text);double temp= Math.Pow(y,0.5);if(textBox2.Text !=null )textBox2.Text ="" ;textBox2.Text = temp.ToString();elsetextBox2.Text = temp.ToString();一个基于 windows phone 7 的简单计算器,同样也是进制转换小数问题,我会不断完善,希望跟小白一起慢慢成长MainPage.xa

29、ml.csusing System;using System.Collections.Generic;using System.Linq;using System;using System.Windows;using System.Windows.Controls;using System.Windows.Documents;第14 页using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Animation;using System.Windows.Shapes;using Micros

30、oft.Phone.Controls;namespace WP_JSpublicpartialclassMainPage :PhoneApplicationPagestringFh ="" ; / 定义符号位double first, second, result;/ 定义 a第一个值, b第二个值,c输出值long dec = 1;/ 定义小数最初为一位/ Constructorpublicvoid anniu(double i)/ 按钮方法if(Fh.Equals("" ) / 是否当前有运算符if(dec = 1)/ 判断是否有小数点first =

31、 first * 10 + i;/ 计算无小数的值elsefirst = first + i / dec;/ 计算有小数的值dec = dec * 10;/ 计算下一个小数的位置textBox1.Text = first.ToString();/ 显示计算的结果else/ 当前有运算符的方法第15 页if(!(result = 0) second = 0; result = 0; /当有计算结果就清除B的值if(dec = 1)/ 判断是否有小数点second = second * 10 + i;/ 计算无小数的值elseif(i = 0)/ 判断在小数位后添加0dec = dec * 10;

32、/ 计算下一个小数的位置elsesecond = second+ i / dec;/ 计算有小数的值dec = dec * 10;/ 计算下一个小数的位置textBox1.Text = second.ToString();/ 显示计算的结果publicvoid js()/ 数学计算的方法if(Fh ="/" ) / 判断是否除数等于0if(second = 0)/ 是则不计算textBox1.Text ="0" ; / 被除数不能为 0return ; / 返回elseresult=first/second;else / 如果不是出发计算则执行其他计算第

33、16 页if(Fh.Equals("+" ) result = first + second; if(Fh.Equals("-") result = first - second; if(Fh.Equals("*") result = first * second; if(Fh.Equals("%") result = first % second; textBox1.Text = result.ToString();/ 显示计算结果first = result;/ 将结果给第一个变量作为publicvoid fh

34、(stringstr)/ 接收运算符的方法if(Fh.Equals("" ) / 当前是否已经有运算符Fh = str; dec = 1;/ 没有则接收运算符 , 小数点失效elsejs();dec = 1; Fh = str;/ 有则计算当前的值 , 小数点失效publicvoid jz_2(stringjg)long temp =Convert .ToInt64(jg);if(temp < 2)textBox2.Text = temp.ToString();elseinti = 0;int array =new int 1000;while (temp >

35、0)arrayi+ = (int )temp % 2;temp /= 2;第17 页int array_1 =new int i;for( intj = i - 1; j >= 0; j-)array_1j = arrayi - 1 - j;/Array.Reverse(array_1);foreach( intkin array_1)textBox2.Text += k.ToString();publicvoid jz_8(stringjg)long temp =Convert .ToInt64(jg);if(temp <8)textBox2.Text = temp.ToStri

36、ng();elseinti = 0;int array =new int 1000;while (temp > 0)arrayi+ = (int )temp % 8;temp /= 8;int array_1 =new int i;for( intj = i - 1; j >= 0; j-)array_1j = arrayi - 1 - j;/Array.Reverse(array_1);foreach( intkin array_1)textBox2.Text += k.ToString();第18 页publicvoid jz_16(stringjg)long temp =Co

37、nvert .ToInt64(jg);if(temp <16)textBox2.Text = temp.ToString();elseinti = 0;int array =new int 1000;while (temp > 0)arrayi+ = (int )temp % 16;temp /= 16;int array_1 =new int i;for( intj = i - 1; j >= 0; j-)array_1j = arrayi - 1 - j;/Array.Reverse(array_1);foreach( intkin array_1)textBox2.Te

38、xt += k.ToString("X" );publicMainPage()InitializeComponent();privatevoidbutton1_Click(objectsender,RoutedEventArgse)anniu(1);privatevoidbutton2_Click(objectsender,RoutedEventArgs第19 页e)anniu(2);privatevoidbutton3_Click(objectsender,RoutedEventArgse)anniu(3);privatevoidbutton4_Click(objects

39、ender,RoutedEventArgse)anniu(4);privatevoidbutton5_Click(objectsender,RoutedEventArgse)anniu(5);privatevoidbutton6_Click(objectsender,RoutedEventArgse)anniu(6);privatevoidbutton7_Click(objectsender,RoutedEventArgse)anniu(7);privatevoidbutton8_Click(objectsender,RoutedEventArgse)anniu(8);privatevoidb

40、utton9_Click(objectsender,RoutedEventArgse)第20 页anniu(9);privatevoidbutton10_Click(objectsender,RoutedEventArgse)if(!textBox1.Text.Equals("0" )anniu(0);privatevoidbutton11_Click(objectsender,RoutedEventArgse)fh("+" );privatevoidbutton12_Click(objectsender,RoutedEventArgse)fh(&quo

41、t;-");privatevoidbutton13_Click(objectsender,RoutedEventArgse)fh("*");privatevoidbutton14_Click(objectsender,RoutedEventArgse)fh("/");privatevoidbutton15_Click(objectsender,RoutedEventArgse)fh("%");privatevoidbutton16_Click(objectsender,RoutedEventArgse)第21 页textBo

42、x1.Text ="0" ; / 清空 TEXTBOX的显示值textBox2.Text="" ;first = 0; second = 0; result = 0; dec = 1; Fh ="" ; /初始化所有值privatevoidbutton17_Click(objectsender,RoutedEventArgs e)if(dec = 1) dec = 10; privatevoidbutton18_Click(objectsender,RoutedEventArgs e)fh("=" );privat

43、evoidbutton19_Click(objectsender,RoutedEventArgs e)if(textBox2.Text !=null )textBox2.Text ="" ;jz_2(textBox1.Text);elsejz_2(textBox1.Text);privatevoidbutton20_Click(objectsender,RoutedEventArgs e)if(textBox2.Text !=null )textBox2.Text ="" ;jz_8(textBox1.Text);第22 页elsejz_8(textBo

44、x1.Text);privatevoidbutton21_Click(objectsender,RoutedEventArgs e)if(textBox2.Text !=null )textBox2.Text ="" ;jz_16(textBox1.Text);elsejz_16(textBox1.Text);privatevoidbutton24_Click(objectsender,RoutedEventArgs e)double temp =Convert .ToDouble(textBox1.Text);temp =Math.Sin(Math.PI) * temp

45、/ 180);if(textBox2.Text !=null )textBox2.Text ="" ;textBox2.Text = temp.ToString();elsetextBox2.Text = temp.ToString();privatevoidbutton22_Click(objectsender,RoutedEventArgs e)double temp =Convert .ToDouble(textBox1.Text);temp =Math.Cos( Math.PI) * temp / 180);第23 页if(textBox2.Text !=null)

46、textBox2.Text ="" ;textBox2.Text = temp.ToString();elsetextBox2.Text = temp.ToString();privatevoidbutton23_Click(objectsender,RoutedEventArgse)double temp =Convert .ToDouble(textBox1.Text);temp =Math.Tan(Math.PI) * temp / 180);if(textBox2.Text !=null)textBox2.Text ="" ;textBox2.T

47、ext = temp.ToString();elsetextBox2.Text = temp.ToString();privatevoidbutton25_Click(objectsender,RoutedEventArgse)double temp =Convert .ToDouble(textBox1.Text);temp =Math.Log(temp);if(textBox2.Text !=null)textBox2.Text ="" ;textBox2.Text = temp.ToString();else第24 页textBox2.Text = temp.ToStri

温馨提示

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

评论

0/150

提交评论