本帖最後由 arthurliuliu 於 2011-12-31 11:02 AM 編輯
- using System;
- using System.Windows.Forms;
- using System.Drawing;
- using System.Media;
- class cal5 : Form
- {
- Button b0 = new Button();
- Button b1 = new Button();
- Button b2 = new Button();
- Button b3 = new Button();
- Button b4 = new Button();
- Button b5 = new Button();
- Button b6 = new Button();
- Button b7 = new Button();
- Button b8 = new Button();
- Button b9 = new Button();
- Button b10 = new Button();
- Button b11 = new Button();
- Button b12 = new Button();
- Button b13 = new Button();
- Button b14 = new Button();
- Button b15 = new Button();
- Button b16 = new Button();
- Button b17 = new Button();
- Button b18 = new Button();
- Button b19 = new Button();
- Button b20 = new Button();
- RadioButton rb1=new RadioButton();
- RadioButton rb2=new RadioButton();
- RadioButton rb3=new RadioButton();
- CheckBox cb1=new CheckBox();
- GroupBox gb1=new GroupBox();
- MainMenu ma=new MainMenu();
- MenuItem me1=new MenuItem("請選擇版面型式");
- MenuItem me11=new MenuItem("基本型");
- MenuItem me12=new MenuItem("工程型");
- TextBox ShowAnswer = new TextBox();
- Color co1 = Color.FromArgb(0,110,180);
- Color co2 = Color.FromArgb(255,217,244);
- SoundPlayer sp0 = new SoundPlayer(@"D:\\test\\0.wav ");
- SoundPlayer sp1 = new SoundPlayer(@"D:\\test\\1.wav ");
- SoundPlayer sp2 = new SoundPlayer(@"D:\\test\\2.wav ");
- SoundPlayer sp3 = new SoundPlayer(@"D:\\test\\3.wav ");
- SoundPlayer sp4 = new SoundPlayer(@"D:\\test\\4.wav ");
- SoundPlayer sp5 = new SoundPlayer(@"D:\\test\\5.wav ");
- SoundPlayer sp6 = new SoundPlayer(@"D:\\test\\6.wav ");
- SoundPlayer sp7 = new SoundPlayer(@"D:\\test\\7.wav ");
- SoundPlayer sp8 = new SoundPlayer(@"D:\\test\\8.wav ");
- SoundPlayer sp9 = new SoundPlayer(@"D:\\test\\9.wav ");
- Timer ti=new Timer();
-
- String digi="";
- String sums;
- double sum=0;
- int fun=0;
- int flag=0;
- int flag2=0;
- int point=6;
- int x=-1,k=0;
- int[] num=new int[37] ;
- public static cal5 frame = new cal5();
- public static void Main()
- {
- Application.Run(frame);
- }
- public cal5()
- {
- b0.Text="0";
- b1.Text="1";
- b2.Text="2";
- b3.Text="3";
- b4.Text="4";
- b5.Text="5";
- b6.Text="6";
- b7.Text="7";
- b8.Text="8";
- b9.Text="9";
- b10.Text=".";
- b11.Text="+";
- b12.Text="-";
- b13.Text="*";
- b14.Text="/";
- b15.Text="CE";
- b16.Text="=";
- b17.Text="sin";
- b18.Text="開始";
- b19.Text="結束";
- b20.Text="記錄";
- rb1.Text="不顯示小數點";
- rb2.Text="顯示 5 位數小數點";
- rb3.Text="顯示全部小數點";
- cb1.Text="Inv";
- ma.MenuItems.Add(me1);
- me1.MenuItems.Add(me11);
- me1.MenuItems.Add(me12);
- Menu=ma;
- ShowAnswer.Location = new Point(20,20);
- ShowAnswer.Size=new Size(230,30);
- ShowAnswer.Text="0";
- ShowAnswer.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
- ShowAnswer.ReadOnly=true;
- ShowAnswer.Focus();
- rb2.Checked=true;
- b0.Location = new Point(20,60);
- b0.Size=new Size(30,30);
- b0.BackColor=Color.FromArgb(170,230,250);
- b1.Location = new Point(70,60);
- b1.Size=new Size(30,30);
- b1.BackColor=Color.FromArgb(170,230,250);
- b2.Location = new Point(120,60);
- b2.Size=new Size(30,30);
- b2.BackColor=Color.FromArgb(170,230,250);
- b3.Location = new Point(170,60);
- b3.Size=new Size(30,30);
- b3.BackColor=Color.FromArgb(170,230,250);
- b4.Location = new Point(220,60);
- b4.Size=new Size(30,30);
- b4.BackColor=Color.FromArgb(170,230,250);
- b5.Location = new Point(20,100);
- b5.Size=new Size(30,30);
- b5.BackColor=Color.FromArgb(170,230,250);
- b6.Location = new Point(70,100);
- b6.Size=new Size(30,30);
- b6.BackColor=Color.FromArgb(170,230,250);
- b7.Location = new Point(120,100);
- b7.Size=new Size(30,30);
- b7.BackColor=Color.FromArgb(170,230,250);
- b8.Location = new Point(170,100);
- b8.Size=new Size(30,30);
- b8.BackColor=Color.FromArgb(170,230,250);
- b9.Location = new Point(220,100);
- b9.Size=new Size(30,30);
- b9.BackColor=Color.FromArgb(170,230,250);
- b10.Location = new Point(20,140);
- b10.Size=new Size(30,30);
- b10.BackColor=Color.FromArgb(170,230,250);
- b11.Location = new Point(70,140);
- b11.Size=new Size(30,30);
- b11.BackColor=Color.FromArgb(192,192,192);
- b12.Location = new Point(120,140);
- b12.Size=new Size(30,30);
- b12.BackColor=Color.FromArgb(192,192,192);
- b13.Location = new Point(170,140);
- b13.Size=new Size(30,30);
- b13.BackColor=Color.FromArgb(192,192,192);
- b14.Location = new Point(220,140);
- b14.Size=new Size(30,30);
- b14.BackColor=Color.FromArgb(192,192,192);
- b15.Location = new Point(20,180);
- b15.Size=new Size(80,30);
- b15.BackColor=Color.FromArgb(255,166,166);
- b16.Location = new Point(120,180);
- b16.Size=new Size(130,30);
- b16.BackColor=Color.FromArgb(255,166,166);
- b17.Location = new Point(170,223);
- b17.Size=new Size(80,30);
- b17.BackColor=Color.FromArgb(200,10,10);
- b17.ForeColor=Color.White;
- b18.Location = new Point(170,290);
- b18.Size=new Size(40,30);
- b19.Location = new Point(220,290);
- b19.Size=new Size(40,30);
- b20.Location = new Point(220,260);
- b20.Size=new Size(40,25);
- b20.BackColor=Color.FromArgb(230,20,20);
- b20.ForeColor=Color.White;
- rb1.Location = new Point(10,10);
- rb1.Size=new Size(120,30);
- rb2.Location = new Point(10,35);
- rb2.Size=new Size(125,30);
- rb3.Location = new Point(10,60);
- rb3.Size=new Size(120,30);
- gb1.Location = new Point(20,215);
- gb1.Size=new Size(140,95);
- cb1.Location = new Point(170,260);
- cb1.Size=new Size(80,30);
- cb1.ForeColor=Color.Red;
- Controls.Add(ShowAnswer);
- Controls.Add(b0);
- Controls.Add(b1);
- Controls.Add(b2);
- Controls.Add(b3);
- Controls.Add(b4);
- Controls.Add(b5);
- Controls.Add(b6);
- Controls.Add(b7);
- Controls.Add(b8);
- Controls.Add(b9);
- Controls.Add(b10);
- Controls.Add(b11);
- Controls.Add(b12);
- Controls.Add(b13);
- Controls.Add(b14);
- Controls.Add(b15);
- Controls.Add(b16);
- Controls.Add(b17);
- Controls.Add(b18);
- Controls.Add(b19);
- Controls.Add(b20);
- gb1.Controls.Add(rb1);
- gb1.Controls.Add(rb2);
- gb1.Controls.Add(rb3);
- Controls.Add(gb1);
- Controls.Add(cb1);
- ShowAnswer.KeyPress +=new KeyPressEventHandler(TextOnPress);
- b0.Click +=new EventHandler(ButtonOnClick0);
- b1.Click +=new EventHandler(ButtonOnClick1);
- b2.Click +=new EventHandler(ButtonOnClick2);
- b3.Click +=new EventHandler(ButtonOnClick3);
- b4.Click +=new EventHandler(ButtonOnClick4);
- b5.Click +=new EventHandler(ButtonOnClick5);
- b6.Click +=new EventHandler(ButtonOnClick6);
- b7.Click +=new EventHandler(ButtonOnClick7);
- b8.Click +=new EventHandler(ButtonOnClick8);
- b9.Click +=new EventHandler(ButtonOnClick9);
- b10.Click +=new EventHandler(ButtonOnClick);
- b11.Click +=new EventHandler(ButtonOnClick);
- b12.Click +=new EventHandler(ButtonOnClick);
- b13.Click +=new EventHandler(ButtonOnClick);
- b14.Click +=new EventHandler(ButtonOnClick);
- b15.Click +=new EventHandler(ButtonOnClick);
- b16.Click +=new EventHandler(ButtonOnClick);
- b17.Click +=new EventHandler(ButtonOnClick);
- b18.Click +=new EventHandler(ButtonOnClick10);
- b19.Click +=new EventHandler(ButtonOnClick11);
- b20.Click +=new EventHandler(ButtonOnClick12);
- rb1.Click +=new EventHandler(RadioOnClick);
- rb2.Click +=new EventHandler(RadioOnClick);
- rb3.Click +=new EventHandler(RadioOnClick);
- cb1.Click +=new EventHandler(CheckOnClick);
- me11.Click +=new EventHandler(MenuOnClick1);
- me12.Click +=new EventHandler(MenuOnClick1);
- ti.Tick += new EventHandler(TimerOnTick);
- ti.Interval=1000;
-
-
- Text = "中華計算機";
- Size = new Size(275,270);
- Location = new Point(250,150);
- BackColor= Color.FromArgb(0,110,180);
- FormBorderStyle = FormBorderStyle.FixedSingle;
- StartPosition=FormStartPosition.Manual;
- }
- void TimerOnTick(Object sender, System.EventArgs e)
- {
- int y=0,z=0;
- x++;
- if(x==k)
- {
- b19.PerformClick();
- b18.PerformClick();
- return;
- }
- if(x>0)
- y=num[x-1];
- else
- y=num[k-1];
-
- z=num[x];
-
- switch(y)
- {
- case 0:b0.FlatStyle=FlatStyle.Standard;
- b0.Refresh();
- for(int c=0;c<50000000;c++);
- break;
- case 1:b1.FlatStyle=FlatStyle.Standard;
- b1.Refresh();
- for(int c=0;c<50000000;c++);
- break;
- case 2:b2.FlatStyle=FlatStyle.Standard;
- b2.Refresh();
- for(int c=0;c<50000000;c++);
- break;
- case 3:b3.FlatStyle=FlatStyle.Standard;
- b3.Refresh();
- for(int c=0;c<50000000;c++);
- break;
- case 4:b4.FlatStyle=FlatStyle.Standard;
- b4.Refresh();
- for(int c=0;c<50000000;c++);
- break;
- case 5:b5.FlatStyle=FlatStyle.Standard;
- b5.Refresh();
- for(int c=0;c<50000000;c++);
- break;
- case 6:b6.FlatStyle=FlatStyle.Standard;
- b6.Refresh();
- for(int c=0;c<50000000;c++);
- break;
- case 7:b7.FlatStyle=FlatStyle.Standard;
- b7.Refresh();
- for(int c=0;c<50000000;c++);
- break;
- case 8:b8.FlatStyle=FlatStyle.Standard;
- b8.Refresh();
- for(int c=0;c<50000000;c++);
- break;
- case 9:b9.FlatStyle=FlatStyle.Standard;
- b9.Refresh();
- for(int c=0;c<50000000;c++);
- break;
- }
-
- switch(z)
- {
- case 0:b0.FlatStyle=FlatStyle.Flat;
- b0.PerformClick();
- break;
- case 1:b1.FlatStyle=FlatStyle.Flat;
- b1.PerformClick();
- break;
- case 2:b2.FlatStyle=FlatStyle.Flat;
- b2.PerformClick();
- break;
- case 3:b3.FlatStyle=FlatStyle.Flat;
- b3.PerformClick();
- break;
- case 4:b4.FlatStyle=FlatStyle.Flat;
- b4.PerformClick();
- break;
- case 5:b5.FlatStyle=FlatStyle.Flat;
- b5.PerformClick();
- break;
- case 6:b6.FlatStyle=FlatStyle.Flat;
- b6.PerformClick();
- break;
- case 7:b7.FlatStyle=FlatStyle.Flat;
- b7.PerformClick();
- break;
- case 8:b8.FlatStyle=FlatStyle.Flat;
- b8.PerformClick();
- break;
- case 9:b9.FlatStyle=FlatStyle.Flat;
- b9.PerformClick();
- break;
-
- }
-
- }
- void ButtonOnClick0(Object sender, System.EventArgs e)
- {
- ShowAnswer.Focus();
- set('0');
- sp0.Play();
- }
- void ButtonOnClick1(Object sender, System.EventArgs e)
- {
- ShowAnswer.Focus();
- set('1');
- sp1.Play();
- }
- void ButtonOnClick2(Object sender, System.EventArgs e)
- {
- ShowAnswer.Focus();
- set('2');
- sp2.Play();
- }
- void ButtonOnClick3(Object sender, System.EventArgs e)
- {
- ShowAnswer.Focus();
- set('3');
- sp3.Play();
- }
- void ButtonOnClick4(Object sender, System.EventArgs e)
- {
- ShowAnswer.Focus();
- set('4');
- sp4.Play();
- }
- void ButtonOnClick5(Object sender, System.EventArgs e)
- {
- ShowAnswer.Focus();
- set('5');
- sp5.Play();
- }
- void ButtonOnClick6(Object sender, System.EventArgs e)
- {
- ShowAnswer.Focus();
- set('6');
- sp6.Play();
- }
- void ButtonOnClick7(Object sender, System.EventArgs e)
- {
- ShowAnswer.Focus();
- set('7');
- sp7.Play();
- }
- void ButtonOnClick8(Object sender, System.EventArgs e)
- {
- ShowAnswer.Focus();
- set('8');
- sp8.Play();
- }
- void ButtonOnClick9(Object sender, System.EventArgs e)
- {
- ShowAnswer.Focus();
- set('9');
- sp9.Play();
- }
- void ButtonOnClick10(Object sender, System.EventArgs e)
- {
- ShowAnswer.Focus();
- x=-1;
- sum=0;
- fun=0;
- digi="";
- ShowAnswer.Text="0";
- ti.Enabled=true;
- }
- void ButtonOnClick11(Object sender, System.EventArgs e)
- {
- ShowAnswer.Focus();
- ShowAnswer.Text="0";
- ti.Enabled=false;
- }
- void ButtonOnClick12(Object sender, System.EventArgs e)
- {
- ShowAnswer.Focus();
- char[] num2=digi.ToCharArray();
- k=num2.Length;
- for(int i=0;i<k;i++)
- num=(int)num2-48;
-
- }
- void ButtonOnClick(Object sender, System.EventArgs e)
- {
- ShowAnswer.Focus();
- Button bu=(Button) sender;
- if(bu==b10)
- set('.');
- if(bu==b11)
- {
- if(fun==0 && flag==0)
- cal1(1);
- if(fun!=0 && flag==0)
- cal2(fun,1);
- }
- if(bu==b12)
- {
- if(digi=="")
- set('-');
- else if(fun==0 && flag==0)
- cal1(2);
- else if(fun!=0 && flag==0)
- cal2(fun,2);
- }
- if(bu==b13)
- {
- if(fun==0 && flag==0)
- cal1(3);
- if(fun!=0 && flag==0)
- cal2(fun,3);
- }
- if(bu==b14)
- {
- if(fun==0 && flag==0 )
- cal1(4);
- else if(fun!=0 && flag==0)
- cal2(fun,4);
- }
- if(bu==b15)
- {
- sum=0;
- fun=0;
- digi="";
- ShowAnswer.Text="0";
- }
- if(bu==b16)
- {
- cal2(fun,0);
- digi=sum.ToString();
- }
- if(bu==b17)
- {
- double x=double.Parse(digi);
- if(flag2==1)
- {
- sum=Math.Asin(x)*180/Math.PI;
- cb1.Checked=false;
- flag2=0;
- }
- else
- {
- x=x%360;
- if(x>=0 && x<=90)
- sum=Math.Sin(x*Math.PI/180);
- if(x>90 && x<=180)
- sum=Math.Sin((180-x)*Math.PI/180);
- if(x>180 && x<=270)
- sum=-1*Math.Sin((x-180)*Math.PI/180);
- if(x>270 && x<=360)
- sum=-1*Math.Sin((360-x)*Math.PI/180);
- }
- sums=sum.ToString();
- sums=conv(sums,point);
- ShowAnswer.Text=sums;
- fun=0;
- digi=sum.ToString();
- }
-
-
- }
-
- void TextOnPress(Object sender, System.Windows.Forms.KeyPressEventArgs e)
- {
-
- if(e.KeyChar == '0')
- set('0');
- if(e.KeyChar == '1')
- set('1');
- if(e.KeyChar == '2')
- set('2');
- if(e.KeyChar == '3')
- set('3');
- if(e.KeyChar == '4')
- set('4');
- if(e.KeyChar == '5')
- set('5');
- if(e.KeyChar == '6')
- set('6');
- if(e.KeyChar == '7')
- set('7');
- if(e.KeyChar == '8')
- set('8');
- if(e.KeyChar == '9')
- set('9');
- if(e.KeyChar == '.')
- set('.');
- if(e.KeyChar == '+')
- {
- if(fun==0 && flag==0)
- cal1(1);
- if(fun!=0 && flag==0)
- cal2(fun,1);
- }
- if(e.KeyChar == '-')
- {
- if(digi=="")
- set('-');
- else if(fun==0 && flag==0)
- cal1(2);
- else if(fun!=0 && flag==0)
- cal2(fun,2);
-
- }
- if(e.KeyChar == '*')
- {
- if(fun==0 && flag==0)
- cal1(3);
- if(fun!=0 && flag==0)
- cal2(fun,3);
- }
- if(e.KeyChar == '/')
- {
- if(fun==0 && flag==0)
- cal1(4);
- if(fun!=0 && flag==0)
- cal2(fun,4);
- }
- if(e.KeyChar == (char)27)
- {
- sum=0;
- fun=0;
- digi="";
- ShowAnswer.Text="0";
- }
- if(e.KeyChar == (char)13)
- {
- cal2(fun,0);
- digi=sum.ToString();
- }
- if(e.KeyChar == '=')
- {
- cal2(fun,0);
- digi=sum.ToString();
- }
- if(e.KeyChar == 'S' || e.KeyChar == 's')
- {
- double x=double.Parse(digi);
- if(flag2==1)
- {
- sum=Math.Asin(x)*180/Math.PI;
- cb1.Checked=false;
- flag2=0;
- }
- else
- {
- x=x%360;
- if(x>=0 && x<=90)
- sum=Math.Sin(x*Math.PI/180);
- if(x>90 && x<=180)
- sum=Math.Sin((180-x)*Math.PI/180);
- if(x>180 && x<=270)
- sum=-1*Math.Sin((x-180)*Math.PI/180);
- if(x>270 && x<=360)
- sum=-1*Math.Sin((360-x)*Math.PI/180);
- }
- sums=sum.ToString();
- sums=conv(sums,point);
- ShowAnswer.Text=sums;
- fun=0;
- digi=sum.ToString();
- }
- if(e.KeyChar == 'I' || e.KeyChar == 'i')
- if(cb1.Checked==true)
- {
- cb1.Checked=false;
- flag2=0;
- }
- else
- {
- cb1.Checked=true;
- flag2=1;
- }
-
- }
-
- void RadioOnClick(Object sender, System.EventArgs e)
- {
- ShowAnswer.Focus();
- RadioButton ra=(RadioButton) sender;
- if(ra==rb1)
- {
- point=0;
- if(sum==0)
- sums=digi;
- else
- sums=sum.ToString();
- sums=conv(sums,point);
- ShowAnswer.Text=sums;
- }
- if(ra==rb2)
- {
- point=6;
- if(sum==0)
- sums=digi;
- else
- sums=sum.ToString();
- sums=conv(sums,point);
- ShowAnswer.Text=sums;
- }
- if(ra==rb3)
- {
- point=30;
- if(sum==0)
- sums=digi;
- else
- sums=sum.ToString();
- sums=conv(sums,point);
- ShowAnswer.Text=sums;
- }
- }
-
- void CheckOnClick(Object sender, System.EventArgs e)
- {
- ShowAnswer.Focus();
- if(cb1.Checked==true)
- flag2=1;
- else
- flag2=0;
- }
- public void set(char a)
- {
- digi+=a;
- flag=0;
- ShowAnswer.Clear();
- ShowAnswer.Text=digi;
- }
- public void cal1(int a)
- {
- sum=double.Parse(digi);
- fun=a;
- digi="";
- flag=1;
- }
- public void cal2(int a,int b)
- {
- switch(a)
- {
- case 1:
- sum=sum+double.Parse(digi);
- sums=sum.ToString();
- sums=conv(sums,point);
- ShowAnswer.Text=sums;
- fun=b;
- digi="";
- break;
- case 2:
- sum=sum-double.Parse(digi);
- sums=sum.ToString();
- sums=conv(sums,point);
- ShowAnswer.Text=sums;
- fun=b;
- digi="";
- break;
- case 3:
- sum=sum*double.Parse(digi);
- sums=sum.ToString();
- sums=conv(sums,point);
- ShowAnswer.Text=sums;
- fun=b;
- digi="";
- break;
- case 4:
- sum=sum/double.Parse(digi);
- sums=sum.ToString();
- sums=conv(sums,point);
- ShowAnswer.Text=sums;
- fun=b;
- digi="";
- break;
- }
- }
- public String conv(String a,int b)
- {
- int c=a.Length;
- int d=a.LastIndexOf(".");
- int e=0;
- int x=0;
- int y=0;
- if(d==-1)
- e=c;
- else
- {
- x=c-(c-d);
- y=c-x;
- if(y>b)
- y=b;
- e=x+y;
- }
- return a.Substring(0,e);
- }
- void MenuOnClick1(Object sender, System.EventArgs e)
- {
- MenuItem mu=(MenuItem) sender;
- if(mu.Text=="基本型")
- {
- frame.Size=new Size(275,270);
- frame.BackColor=co1;
-
- }
- if(mu.Text=="工程型")
- {
- frame.Size=new Size(275,390);
- frame.BackColor=co2;
-
- }
- }
- }
複製代碼
音訊問題可解決
煩請指出程式碼錯誤處OR解決辦法
也感謝版主大大的回答!:)code沒包,板主代為編輯。
arthurliuliu
... |