开发工具:
文件大小: 143kb
下载次数: 0
上传时间: 2009-02-27
详细说明: 一个C#计算器 最基本的 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace BfirstApplication { public partial class Form2 : Form { public Form2() { InitializeComponent(); } private void Form2_Load(object sender, EventArgs e) { } private void num_click(object sender, EventArgs e) { Button b = (Button)sender; if (dit >= 1 && b.Text == ".") { return; } if (dit < 1 && textBox1.Text.Length > 0 && textBox1.Text[textBox1.Text.Length - 1] == '.') { textBox1.Text = textBox1.Text.Remove(textBox1.Text.Length - 1); } if (b.Text == ".") { dit++; } if (!add) { textBox1.Text = ""; add = true;} textBox1.AppendText(b.Text); if (textBox1.Text == ".") textBox1.Text = "0."; if (dit < 1 && textBox1.Text != "0.") textBox1.AppendText("."); } private void textBox1_TextChanged(object sender, EventArgs e) { } private void oper_click(object sender, EventArgs e) { Button b = (Button)sender; if (b.Text == "+") { if (add) f(); sum1 = sum = Convert.ToDouble(textBox1.Text); flag = 0; add = false; dit = 0; } if (b.Text == "-") { if (add) f(); sum1 = sum = Convert.ToDouble(textBox1.Text); flag = 1; add = false; dit = 0; } if (b.Text == "*") { if (add) f(); sum1 = sum = Convert.ToDouble(textBox1.Text); flag = 2; add = false; dit = 0; } if (b.Text == "/") { if(add)f(); sum1 = sum = Convert.ToDouble(textBox1.Text); flag = 3; add = false; dit = 0; } if (b.Text == "sqrt") { sum = Math.Sqrt(Convert.ToDouble(textBox1.Text)); textBox1.Text = Convert.ToString(sum); int temp = (int)sum; double t = (double)temp; if (sum == t) { textBox1.AppendText("."); } flag = -1; } if (b.Text == "%") { sum = Convert.ToDouble(textBox1.Text); sum *= sum/100; textBox1.Text = Convert.ToString(sum); int temp = (int)sum; double t = (double)temp; if (sum == t) { textBox1.AppendText("."); } flag = -1; } if (b.Text == "1/x") { sum = 1.0/Convert.ToDouble(textBox1.Text); textBox1.Text = Convert.ToString(sum); int temp = (int)sum; double t = (double)temp; if (sum == t) { textBox1.AppendText("."); } flag = -1; } if (b.Text == "C") { sum = 0; sum1 = 0; textBox1.Text = "0."; add = false; flag = -1; dit = 0; } if (b.Text == "CE") { textBox1.Text = "0."; add = false; dit = 0; } if(b.Text=="+\\-"){ if (textBox1.Text.Length == 0) return; sum=Convert.ToDouble(textBox1.Text); sum=-sum; textBox1.Text=Convert.ToString(sum); int temp = (int)sum; double t = (double)temp; if (sum == t) { textBox1.AppendText("."); } } if (b.Text == "Backspace") { int length = textBox1.Text.Length; /*char[] des=textBox1.Text.ToCharArray(); //注释掉的代码也可实现所要求的功能 * if(length>0)des[length - 1] = '\0'; * string str=new string(des); * textBox1.Text = str; */ if (length > 0&&add==true) { if (textBox1.Text[length - 1] == '.') dit = 0; if (length > 2) textBox1.Text = textBox1.Text.Remove(length - 2); else textBox1.Text = "0"; sum = Convert.ToDouble(textBox1.Text); int temp = (int)sum; double t = (double)temp; if (sum == t) { textBox1.AppendText("."); } } if (textBox1.Text.Length==2) { textBox1.Text = "0."; add = false; } } if (b.Text == "=") { if (add) { sum1 = Convert.ToDouble(textBox1.Text); f(); add = false; } else { if (flag == 0) sum = Convert.ToDouble(textBox1.Text) + sum1; if (flag == 1) sum = Convert.ToDouble(textBox1.Text) - sum1; if (flag == 2) sum = Convert.ToDouble(textBox1.Text) * sum1; if (flag == 3) sum = Convert.ToDouble(textBox1.Text) / sum1; textBox1.Text = Convert.ToString(sum); int temp = (int)sum; double t = (double)temp; if (sum == t) { textBox1.AppendText("."); } } } } private void Form2_Click(object sender, EventArgs e) { } private void toolStripMenuItem1_Click(object sender, EventArgs e) { Help.ShowHelp(textBox1 ,"file://C:\\WINDOWS\\Help\\calc.chm"); } private void 科学型ToolStripMenuItem_Click(object sender, EventArgs e) { Help.ShowHelp(textBox1,"file://C:\\WINDOWS\\system32\\calc.exe"); } private void 复制ToolStripMenuItem_Click(object sender, EventArgs e) { copy = textBox1.Text; System.Drawing.Text.HotkeyPrefix x=new System.Drawing.Text.HotkeyPrefix(); cop = true; } private void 粘贴ToolStripMenuItem_Click(object sender, EventArgs e) { if (cop) textBox1.Text = copy; } private void button4_Click(object sender, EventArgs e) { Button b = (Button)sender; if (b.Text == "MC") { mem = 0; textBox2.Text = ""; } if (b.Text == "MR") { textBox1.Text = Convert.ToString(mem); int temp = (int)mem; double t = (double)temp; if (mem == t) { textBox1.AppendText("."); } add = false; } if (b.Text == "MS") { mem = Convert.ToDouble(textBox1.Text); textBox1.Text = "0."; textBox2.Text = "M"; dit = 0; add = false; } if (b.Text == "M+") { mem += Convert.ToDouble(textBox1.Text); } } private void toolStripMenuItem2_Click(object sender, EventArgs e) { AboutBox1 b = new AboutBox1(); b.ShowDialog(); } } } ...展开收缩
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.