照书编了个计算器,不会修改
是用Form.cs和Form.cs[Design]做的,添加了一些button,然后双击各个button添加代码程序代码:
using System; using System.Collections.Generic; using using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace calculator { public void PressNumber(string KeyType) { SelectWays=0; Number1=""; Number2=""; Screen.Text=""; NextInput=0; } if(SelectWays==0&&NextInput==0) { Screen.Text=""; NextInput=-1; } if(Screen.Text.Length<15) { Screen.Text+=Keytype; } if((SelectWays==10||SelectWays==100)&&NextInput==2) { Number2=Screen.Text; } public void Operate(String op) { Op_Add=false; Op_Minus=false; Op_Mul=false; Op_Div=false; switch(op) { case"div": Op_Div=true; break; case"mul": Op_Mul=true; break; case"minus": Op_Minus=true; break; case"add": Op_Add=true; break; } } public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void progressBar1_Click(object sender, EventArgs e) { } private void Form1_Load(object sender, EventArgs e) { } private void button16_Click(object sender, EventArgs e) { if (Screen.Text != "0" && Screen.Text.Length < 15) PressNumber("0"); } private void button9_Click(object sender, EventArgs e) { PressNumber("1"); } private void button11_Click(object sender, EventArgs e) { PressNumber("2"); } private void button10_Click(object sender, EventArgs e) { PressNumber("3"); } private void button5_Click(object sender, EventArgs e) { PressNumber("4"); } private void button3_Click(object sender, EventArgs e) { PressNumber("5"); } private void button2_Click(object sender, EventArgs e) { PressNumber("6"); } private void button1_Click(object sender, EventArgs e) { PressNumber("7"); } private void button6_Click(object sender, EventArgs e) { PressNumber("8"); } private void button7_Click(object sender, EventArgs e) { PressNumber("9"); } private void button14_Click(object sender, EventArgs e) { ShowResult(); } public void ShowResult() { if(SelectWays==100||SelectWays==11) { if(Op_Div==true) { } if(Op_Div==true) { Screen.Text="1"; } else if(Op_Mul==true) { Screen.Text=Convert.ToString(Convert.ToDouble(Screen.Text)*Convert.ToDouble(Number1)); } else if(Op_Minus==true) { Screen.Text=Convert.ToString(Convert.ToDouble(Screen.Text)+oConvert.ToDouble(Number1)); } } Number2=""; } } private void button13_Click(object sender, EventArgs e) { Operate("add"); } private void button12_Click(object sender, EventArgs e) { Operate("minus"); } private void button4_Click(object sender, EventArgs e) { Operate("mul"); } private void button8_Click(object sender, EventArgs e) { Operate("div"); } private void button17_Click(object sender, EventArgs e) { Clear(); public void Clear() { Screen.Text="0"; Number1=""; Number2=""; Op_Mul=false; Op_Div=false; } private void button15_Click(object sender, EventArgs e) { foreach(char point in Screen.Text) { if(point=='.') { IsReal=true; break; } if(!IsReal) { if(Screen.Text!="0") PressNumber("."); } else { Screen.Text=""; PressNumber("0."); } IsReal=true; } } }
小弟刚刚接触C#,不会修改,报的错基本都是这两个:
Error 9 Expected class, delegate, enum, interface, or struct
Error 33 'System.Windows.Forms.Screen' does not contain a definition for 'Text'
求教!!!!!