C#计算器,C#小程序,关于编程的

时间:2012-05-12 01:21:27
【文件属性】:

文件名称:C#计算器,C#小程序,关于编程的

文件大小:39KB

文件格式:RAR

更新时间:2012-05-12 01:21:27

c#计算器

简单的C#计算器,但很实用 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace calculator { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Btn_Clear_Click(object sender, EventArgs e) { txt_Result.Text =" "; } private void button0_Click(object sender, EventArgs e) { Button btn=(Button) sender; txt_Result .Text +=btn.Text ; } private void Form1_Load(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { Button btn = (Button)sender; txt_Result.Text += btn.Text; } private void button2_Click(object sender, EventArgs e) { Button btn=(Button) sender; txt_Result .Text +=btn.Text ; } private void button3_Click(object sender, EventArgs e) { Button btn = (Button)sender; txt_Result.Text += btn.Text; } private void button4_Click(object sender, EventArgs e) { Button btn = (Button)sender; txt_Result.Text += btn.Text; } private void button5_Click(object sender, EventArgs e) { Button btn = (Button)sender; txt_Result.Text += btn.Text; } private void button6_Click(object sender, EventArgs e) { Button btn = (Button)sender; txt_Result.Text += btn.Text; } private void button7_Click(object sender, EventArgs e) { Button btn = (Button)sender; txt_Result.Text += btn.Text; } private void button8_Click(object sender, EventArgs e) { Button btn = (Button)sender; txt_Result.Text += btn.Text; } private void button9_Click(object sender, EventArgs e) { Button btn = (Button)sender; txt_Result.Text += btn.Text; } private void btn_Add_Click(object sender, EventArgs e) { Button btn = (Button)sender; txt_Result.Text = txt_Result.Text + " " + btn.Text + " "; } private void btn_Result_Click(object sender, EventArgs e) { double d_result; string s_txt = txt_Result.Text; int space = s_txt.IndexOf(' '); string s1 = s_txt.Substring(0, space); char operation =System. Convert.ToChar(s_txt.Substring((space + 1), 1)); string s2 = s_txt.Substring(space + 3); double arg1 =System . Convert.ToDouble(s1); double arg2 =System . Convert.ToDouble(s2); switch (operation) { case '+': d_result = arg1 + arg2; break; case '-': d_result = arg1 - arg2; break; case '*': d_result = arg1 * arg2; break; case '/': if (arg2 == 0) { throw new ApplicationException(); } else { d_result = arg1 / arg2; } break; default: throw new ApplicationException(); } txt_Result.Text = d_result.ToString(); } private void btn_Sub_Click(object sender, EventArgs e) { Button btn = (Button)sender; txt_Result.Text = txt_Result.Text+ " "+ btn.Text+ " "; } private void btn_cheng_Click(object sender, EventArgs e) { Button btn = (Button)sender; txt_Result.Text = txt_Result.Text + " " + btn.Text+ " "; } private void btn_chu_Click(object sender, EventArgs e) { Button btn = (Button)sender; txt_Result.Text = txt_Result.Text+ " "+ btn.Text + " "; } private void button10_Click(object sender, EventArgs e) { Button btn = (Button)sender; txt_Result.Text = txt_Result.Text + " " + btn.Text + " "; } private void button10_Click_1(object sender, EventArgs e) { } } }


【文件预览】:
C# 计算器
----calculator()
--------Form1.cs(5KB)
--------bin()
--------obj()
--------calculator.csproj(3KB)
--------Properties()
--------Program.cs(469B)
--------calculator.csproj.user(168B)
--------Form1.Designer.cs(14KB)
--------Form1.resx(6KB)
----calculator.suo(20KB)
----calculator.sln(919B)

网友评论

  • 不错的,借鉴用还是很不错的。正如作者所说,确实很简单。。。。。
  • 不错 可以使用
  • 额,挺好的一个程序,就是界面不咋地
  • 下载下来的使用起来还不错的效果的。
  • 清空之后就不能用减的功能
  • 不错,很简单,具备简单的计算功能
  • 还行,代码简单,初学者可以借鉴
  • 看了下,很简单
  • 虽然有些小bug,但是我根据他的源代码自己又做了一个比他的功能更好的。他的代码还是可以借鉴的。
  • 不错,很简单,
  • 不错,很简单,很适合初学者,不过最后的button10干嘛的?貌似木有用啊~~~