CWP7简单计算器-32页精选文档_第1页
CWP7简单计算器-32页精选文档_第2页
CWP7简单计算器-32页精选文档_第3页
CWP7简单计算器-32页精选文档_第4页
CWP7简单计算器-32页精选文档_第5页
已阅读5页,还剩37页未读 继续免费阅读

下载本文档

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

文档简介

1、基于c#W体程序的一个简单计算器,进制转换的小数部分没有完善,初学者,继续努力中 . 各位大侠请指教,各位小白大家互相学习,一起进步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_easypublic partial class F

2、orm1 : Formstring Fh = "" ; / 定义符号位double a, b, c; /定义a第一个值,b第二个值,c输出值long s = 1; / 定义小数最初为一位public Form1()InitializeComponent();public void anniu( double i) / 按钮方法if (Fh.Equals( "" ) / 是否当前有运算符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();/ 显示计算的结果public void js

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

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

6、vert .ToInt64(jg);if (temp < 2)textBox2.Text = temp.ToString();elseint i = 0;int array = new int 1000;while (temp > 0)arrayi+ = (int )temp % 2;temp /= 2;int array_1 = new int i;for ( int j = i - 1; j >= 0; j-)array_1j = arrayi - 1 - j;/Array.Reverse(array_1);foreach ( int k in array_1)textB

7、ox2.Text += k.ToString();public void jz8( string jg) /8 进制转换long temp = Convert .ToInt64(jg);if (temp < 9)textBox2.Text = temp.ToString();elseint i = 0;int array = new int 1000;while (temp > 0)arrayi+ = (int )temp % 8;temp /= 8;int array_1 = new int i;for ( int j = i - 1; j >= 0; j-)array_1

8、j = arrayi - 1 - j;/Array.Reverse(array_1);foreach ( int k in array_1)textBox2.Text += k.ToString();public void jz16( string jg) / 十六进制转换long temp = Convert .ToInt64(jg);if (temp < 16)textBox2.Text = temp.ToString();elseint i = 0;int array = new int 1000; / 浪费空间,节省时间while (temp > 0)arrayi+ = (

9、int )temp % 16;temp /= 16;int array_1 = new int i;for ( int j = i - 1; j >= 0; j-)array_1j = arrayi - 1 - j;foreach ( int k in array_1)textBox2.Text += k.ToString("X" );public long Jiec( long jg) / 阶乘long temp = jg;if (temp = 1)return 1;elselong temp1 = Jiec(temp-1);temp = temp * temp1;

10、return temp;e).Bold);.Bold);private void Form1_Load( object sender, EventArgs textBox1.Font =new Font ( " 宋体 " , 14, FontStyletextBox2.Font =new Font ( " 宋体 " , 14, FontStylethis .Text = " 简单计算器" ;string dir = "imageangry.jpg" ;pictureBox1.Image =Image.FromFil

11、e(dir);pictureBox1.SizeModePictureBoxSizeMode .StretchImage;pictureBox1.Dock =DockStyle .Fill;button1.Text =button2.Text =2; ;button3.Text ="3" ;button4.Text ="4" ;button5.Text ="5" ;button6.Text =button7.Text =button8.Text =button9.Text =button10.Text =button12.Text =b

12、utton13.Text =button14.Text =button15.Text =button16.Text =button17.Text =button18.Text =button19.Text =button11.Text =button20.Text =button21.Text =button22.Text =button23.Text =button24.Text=button25.Text =button25.Font =button26.Text ="C1"7; ;"8" ;"9" ;"0"&

13、quot;%""/""6""1""C2" ;"Sin""Cos""Tan""Log10" ;Lg" ;!;new Font( "" ,10, FontStyle .Bold);"A2"radioButton1.Text =radioButton2.Text =radioButton3.Text =radioButton4.Text =" 二进制" ;&quo

14、t; 八进制" ;" 十六进制 " ;"十 进 制"private void textBox1_TextChanged( objectsender,EventArgs e)textBox1.BackColor =Color .White;textBox1.Enabled =falseprivatevoid textBox2_TextChanged( objectsender,EventArgs e)textBox1.BackColor =textBox1.Enabled =Color .White;false ;private voidanni

15、u(1);private voidanniu(2);private voidanniu(3);private voidanniu(4);private voidbutton19_Click(object sender,EventArgs e)anniu(5);button2_Click(button3_Click(button4_Click(button5_Click(object sender,object sender,object sender,object sender,EventArgs e)EventArgs e)EventArgs e)EventArgs e)private vo

16、id button17_Click( object sender, EventArgs e)anniu(6);private voidanniu(7);private voidanniu(8);private voidanniu(9);button7_Click(button8_Click(button9_Click(private void button10_Click(if (!textBox1.Text.Equals( anniu(0);privatevoid button18_Click(if (s = 1) s = 10; privatevoid button14_Click(fh(

17、 "*" );button14.BackColor =object sender,object sender,object sender,object sender,"0" )object sender,object sender,Color .BlueViolet;private void button15_Click( object sender, fh( "%");button15.BackColor =Color .BlueViolet;private void button12_Click( object sender, f

18、h( "+" );Color .BlueViolet;button12.BackColor =EventArgs e)EventArgs e)EventArgs e)EventArgs e)EventArgs e)EventArgs e)EventArgs e)EventArgs e)private void button13_Click( object sender, EventArgs e)fh( "-" );button13.BackColor =Color .BlueViolet;private void button16_Click( obje

19、ct sender, EventArgs e)fh( "/" );button16.BackColor =Color .BlueViolet;private void button6_Click( object sender, EventArgs e)textBoxl.Text ="0" ; / 清空 TEXTBOX显示值a = 0; b = 0; c = 0; s = 1; Fh ="" ; / 初始化所有值private void button1_Click( object sender, EventArgs e)颜色改变延迟Sy

20、stemColors .Control; / 还原按钮SystemColors .Control;SystemColors .Control;SystemColors .Control;SystemColors .Control;fh( "=" );Thread .Sleep(300); /button12.BackColor =颜色button13.BackColor =button14.BackColor =button15.BackColor =button16.BackColor =private void radioButton1_CheckedChanged(

21、object sender,EventArgs e)if (textBox2.Text != null )textBox2.Text =jz2(textBox1.Text);elsejz2(textBox1.Text);private void radioButton2_CheckedChanged( object sender,EventArgs e)if (textBox2.Text != null )textBox2.Text ="" ;jz8(textBox1.Text);elsejz8(textBox1.Text);private void radioButton

22、3_CheckedChanged( object sender,EventArgs e)if (textBox2.Text != null )textBox2.Text ="" ;jz16(textBox1.Text);elsejz16(textBox1.Text);private void button11_Click( object sender, EventArgs e)textBox2.Text ="" ;private void radioButton4_CheckedChanged( object sender,EventArgs e)tex

23、tBox2.Text = c.ToString();private void button20_Click( object sender, EventArgse)temp =double temp = Convert .ToDouble(textBox1.Text);Math.Sin(3.1415926 * temp / 180);if (textBox2.Text != null )textBox2.Text =textBox2.Text = temp.ToString();elsetextBox2.Text = temp.ToString();private void button21_C

24、lick( object sender, EventArgse)temp =double temp = Convert .ToDouble(textBox1.Text);Math.Cos(3.1415926*temp/180);if (textBox2.Text != null )textBox2.Text =textBox2.Text = temp.ToString();elsetextBox2.Text = temp.ToString();private void button22_Click( object sender, EventArgse)temp =double temp = C

25、onvert .ToDouble(textBox1.Text);Math.Tan(3.1415926*temp/180);if (textBox2.Text != null )textBox2.Text =textBox2.Text = temp.ToString();elsetextBox2.Text = temp.ToString();private void button23_Click( object sender, EventArgs e)double temp = Convert .ToDouble(textBox1.Text);temp = Math.Log10(temp) ;i

26、f (textBox2.Text != null )textBox2.Text ="" ;textBox2.Text = temp.ToString();elsetextBox2.Text = temp.ToString();private void button24_Click( object sender, EventArgs e)double temp = Convert .ToDouble(textBox1.Text);temp = Math.Log(temp);if (textBox2.Text != null )textBox2.Text ="&quo

27、t; ;textBox2.Text = temp.ToString();elsetextBox2.Text = temp.ToString();private void button25_Click( object sender, EventArgs e)long temp = Convert .ToInt64(textBox1.Text);Jiec(temp);if (textBox2.Text != null )textBox2.Text = textBox2.Text = Jiec(temp).ToString();elsetextBox2.Text = Jiec(temp).ToStr

28、ing();private void button26_Click( object sender, 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 的简单计算器,同样也是进制转换小数问题,我会不

29、断完善,希望跟小白一起慢慢成长MainPage.xaml.cs using System;using System.Collections.Generic;using System.Linq;using System;using System.Windows;using System.Windows.Controls;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Animation;using System.Windo

30、ws.Shapes;using Microsoft.Phone.Controls;namespace WP_JSpublic partial class MainPage : PhoneApplicationPagestring Fh = "" ; / 定义符号位double first, second, result; / 定义 a第一个值,b第二个值,c输出值long dec = 1; / 定义小数最初为一位/ Constructor public void anniu( double i) / 按钮方法if (Fh.Equals( "" ) / 是

31、否当前有运算符if (dec = 1) / 判断是否有小数点first = first * 10 + i;/ 计算无小数的值elsefirst = first + i / dec;/ 计算有小数的值dec = dec * 10;/ 计算下一个小数的位置textBox1.Text = first.ToString();/ 显示计算的结果else / 当前有运算符的方法第 36 页当有计算结果就清除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();public void js()/ 数学计算的方法if (Fh = "/" ) / 判断是否除数等于0if (second = 0)/ 是则不计算textBox1.Text =/ 计算有小数的/ 显示计算的结"0" ; / 被除数不能为 0return ; / 返回elseresult=first/second;else / 如果不是出发计算则执行其他计

33、算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;/ 将结果给第一个变量作为public void fh

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

35、temp > 0)arrayi+ = (int )temp % 2;temp /= 2;int array_1 = new int i;for ( int j = i - 1; j >= 0; j-)array_1j = arrayi - 1 - j;/Array.Reverse(array_1);foreach ( int k in array_1)textBox2.Text += k.ToString();public void jz_8( string jg)long temp = Convert .ToInt64(jg);if (temp <8)textBox2.Te

36、xt = temp.ToString();elseint i = 0;int array = new int 1000;while (temp > 0)arrayi+ = (int )temp % 8;temp /= 8;int array_1 = new int i;for ( int j = i - 1; j >= 0; j-)array_1j = arrayi - 1 - j;/Array.Reverse(array_1);foreach ( int k in array_1)textBox2.Text += k.ToString();public void jz_16( s

37、tring jg)long temp = Convert .ToInt64(jg);if (temp <16)textBox2.Text = temp.ToString();elseint i = 0;int array = new int 1000;while (temp > 0)arrayi+ = (int )temp % 16;temp /= 16;int array_1 = new int i;for ( int j = i - 1; j >= 0; j-)array_1j = arrayi - 1 - j;/Array.Reverse(array_1);foreac

38、h ( int k in array_1)textBox2.Text += k.ToString("X" );public MainPage()InitializeComponent();private void button1_Click( object sender, RoutedEventArgse)anniu(1);private void button2_Click( object sender, RoutedEventArgse)anniu(2);private voide)anniu(3);private voide)anniu(4);private void

39、e)anniu(5);private voide)anniu(6);private voide)anniu(7);private voide)anniu(8);private voidbutton3_Click( objectbutton4_Click( objectbutton5_Click( objectbutton6_Click( objectbutton7_Click( objectbutton8_Click( objectbutton9_Click( objecte)sender, RoutedEventArgssender, RoutedEventArgssender, Route

40、dEventArgssender, RoutedEventArgssender, RoutedEventArgssender, RoutedEventArgssender, RoutedEventArgsanniu(9);privatevoid button10_Click( objectsender,RoutedEventArgs e)if (!textBox1.Text.Equals( "0" )anniu(0);private voidRoutedEventArgs e)fh( "+" );private voidRoutedEventArgs e

41、)fh( "-" );private voidRoutedEventArgs e)fh( "*" );private voidRoutedEventArgs e)fh( "/" );private voidRoutedEventArgs e)fh( "%");private voidbutton11_Click( objectbutton12_Click( objectbutton13_Click( objectbutton14_Click( objectbutton15_Click( objectbutton16

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

43、18_Click(objectsender,RoutedEventArgse)fh(IIII);privatevoidbutton19_Click(objectsender,RoutedEventArgse)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(textBo

44、x1.Text);sender,sender,sender,elsejz_8(textBox1.Text);private void button21_Click( objectRoutedEventArgs e)if (textBox2.Text != null )textBox2.Text ="" ;jz_16(textBox1.Text);elsejz_16(textBox1.Text);private void button24_Click( objectRoutedEventArgs e)double temp = Convert .ToDouble(textBo

45、x1.Text);temp = Math.Sin( Math.PI) * temp / 180);if (textBox2.Text != null )textBox2.Text ="" ;textBox2.Text = temp.ToString();elsetextBox2.Text = temp.ToString();private void button22_Click( objectRoutedEventArgs e)double temp = Convert .ToDouble(textBox1.Text);temp = Math.Cos( Math.PI) *

46、 temp / 180);if (textBox2.Text != null )textBox2.Text ="" ;textBox2.Text = temp.ToString();elsetextBox2.Text = temp.ToString();private void button23_Click( object sender,RoutedEventArgs e)double temp = Convert .ToDouble(textBox1.Text);temp = Math.Tan( Math.PI) * temp / 180);if (textBox2.Te

47、xt != null )textBox2.Text ="" ;textBox2.Text = temp.ToString();elsetextBox2.Text = temp.ToString();private void button25_Click( object sender,RoutedEventArgs e)double temp = Convert .ToDouble(textBox1.Text);temp = Math.Log(temp);if (textBox2.Text != null )textBox2.Text ="" ;textB

48、ox2.Text = temp.ToString();elsetextBox2.Text = temp.ToString();sender,private void button26_Click( objectRoutedEventArgs e)double temp = Convert .ToDouble(textBox1.Text);temp = Math.Log10(temp);if (textBox2.Text != null )textBox2.Text ="" ;textBox2.Text = temp.ToString();elsetextBox2.Text

49、= temp.ToString();MainPage.xaml( 就是添加控件,把按钮什么的拖进去就有代码了 )<phone: PhoneApplicationPagex : Class ="WP_JS.MainPage"xmlns="http:/schemas.microsoft/winfx/2006/xaml/presentation"xmlns : x="http:/schemas.microsoft/winfx/2006/xaml"xmlns: phone="clr-namespace:Microsoft.Ph

50、one.Controls;assembly=Microsoft.Phone"xmlns: shell ="clr-namespace:Microsoft.Phone.Shell;assembly=Micro soft.Phonexmlns : d="http:/schemas.microsoft/expression/blend/2008" xmlns: mc="/markup-compatibilit y/2006"mc: Ignorable ="d"

51、; d : DesignWidth ="480" d : DesignHeight ="768"FontFamily =" StaticResource PhoneFontFamilyNormal "FontSize =" StaticResource PhoneFontSizeNormal "Foreground =" StaticResource PhoneForegroundBrush "SupportedOrientations ="Portrait" Orienta

52、tion ="Portrait"shell : SystemTray.IsVisible ="True"><!-LayoutRootis the root grid where all page content isplaced-><Grid x : Name="LayoutRoot" Background ="Transparent"><Grid.RowDefinitions ><RowDefinition Height ="Auto"/>

53、<RowDefinition Height ="*"/></ Grid.RowDefinitions ><!-TitlePanel contains the name of the application and page title-><StackPanelx: Name="TitlePanel"Grid.Row ="0"Margin ="12,17,0,28"></ StackPanel ><!-ContentPanel - place addi

54、tional content here-><Gridx: Name="ContentPanel"Grid.Row ="1"Margin ="12,0,12,0"><TextBox Height ="111" HorizontalAlignment ="LeftName="textBox1Text ="" VerticalAlignment ="Top" Width ="450"FontSize ="48

55、" /><ButtonContent ="1"Height ="74"Name="button1"HorizontalAlignment ="Left" Margin ="6,117,0,0"VerticalAlignment ="Top" Width ="79" Click ="button1_Click" /><ButtonContent ="2"Height ="74

56、"HorizontalAlignment ="Left" Margin ="91,117,0,0" Name="button2"VerticalAlignment ="Top" Width ="79" Click ="button2_Click" /><ButtonContent ="3"Height ="74"HorizontalAlignment ="Left" Margin ="

57、191,117,0,0" Name="button3"VerticalAlignment ="Top" Width ="79" Click ="button3_Click" /><ButtonContent ="4"Height ="74HorizontalAlignment ="Left" Margin ="286,117,0,0" Name="button4"VerticalAlignment =&q

58、uot;Top" Width ="79" Click ="button4_Click" /><ButtonContent ="5"Height ="74HorizontalAlignment ="Left" Margin ="371,117,0,0" Name="button5"VerticalAlignment ="Top" Width ="79" Click ="button5_Click" /><ButtonContent ="6"Height ="74HorizontalAlignment ="Left" Margin ="6,197,0,0" Name="button6"第 37 页VerticalAl

温馨提示

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

评论

0/150

提交评论