文件名称: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)