C#简易计算器

huminghua 2010-12-09 01:02:26
如题
...全文
86 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wanggenhu0 2010-12-09
  • 打赏
  • 举报
回复
这网上太多 了
tercelstar 2010-12-09
  • 打赏
  • 举报
回复
代码有点多,贴不上去,我的资源下面有一个计算器的实现源码,你可以看一下
tsp860901 2010-12-09
  • 打赏
  • 举报
回复
这是哥 以前做的 你看看对不对 !
tsp860901 2010-12-09
  • 打赏
  • 举报
回复
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace 计算器 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private double x;// 运算前数值 private double y;// 运算后数值 private string js;//运算符 private void Form1_Load(object sender, EventArgs e) { textBox1.Text = ""; } private void but_click(string text) {//操作数值按钮,文本框的显示 if (js == "") { textBox1.Text = textBox1.Text + text; } else { textBox1.Text = text; } } //以下是+-*/ private void button13_Click(object sender, EventArgs e) { x = Convert.ToDouble(textBox1.Text); js = button13.Text; } private void button12_Click(object sender, EventArgs e) { x = Convert.ToDouble(textBox1.Text); js = button12.Text; } private void button11_Click(object sender, EventArgs e) { x = Convert.ToDouble(textBox1.Text); js = button11.Text; } private void button14_Click(object sender, EventArgs e) { x = Convert.ToDouble(textBox1.Text); js = button14.Text; } //清除按钮 private void button16_Click(object sender, EventArgs e) { textBox1.Text = ""; x = 0; y = 0; js = ""; } //等号按钮 private void button15_Click(object sender, EventArgs e) { y = Convert.ToDouble(textBox1.Text); if (js == "/" && y == 0) { MessageBox.Show("除数为0错误!"); return; } else { switch (js) { case "+": textBox1.Text = (x + y).ToString(); break; case "-": textBox1.Text = (x - y).ToString(); break; case "*": textBox1.Text = (x * y).ToString(); break; } } } //以下数值按钮调用but_click()事件 ,主要是怎么把下面的简化,只写一个??? private void button9_Click(object sender, EventArgs e) { but_click(this.button9.Text); } private void button6_Click(object sender, EventArgs e) { but_click(this.button6.Text); } private void button8_Click(object sender, EventArgs e) { but_click(this.button8.Text); } private void button7_Click(object sender, EventArgs e) { but_click(this.button7.Text); } private void button5_Click(object sender, EventArgs e) { but_click(this.button5.Text); } private void button4_Click(object sender, EventArgs e) { but_click(this.button4.Text); } private void button3_Click(object sender, EventArgs e) { but_click(this.button3.Text); } private void button2_Click(object sender, EventArgs e) { but_click(this.button2.Text); } private void button1_Click(object sender, EventArgs e) { but_click(this.button1.Text); } private void button10_Click(object sender, EventArgs e) { but_click(this.button10.Text); } } }

110,499

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧