C#写计算器的时候,怎么把运算显示出来。

花陌开1 2014-06-26 02:51:41
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
char nu;
double temp, num;

public Form1()
{
InitializeComponent();
}

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{

}

private void button10_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "0";
}

private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "1";
}

private void button2_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "2";
}

private void button3_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "3";
}

private void button4_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "4";
}

private void button5_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "5";
}

private void button6_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "6";
}

private void button7_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "7";
}

private void button8_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "8";
}

private void button9_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "9";
}

private void button11_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + ".";
}

private void button12_Click(object sender, EventArgs e)
{
temp = double.Parse(textBox1.Text);
switch (nu)
{
case '+':
num += temp;
break;
case '-':
num -= temp;
break;
case '*':
num *= temp;
break;
case '/':
num /= temp;
break;
}
textBox1.Text = num.ToString();
nu = ' ';
num = 0;
temp = 0;

}

private void button13_Click(object sender, EventArgs e)
{
num = double.Parse(textBox1.Text);
nu = '+';
textBox1.Text = null;

}

private void button14_Click(object sender, EventArgs e)
{
num = double.Parse(textBox1.Text);
nu = '-';
textBox1.Text = null;
}

private void button15_Click(object sender, EventArgs e)
{
num = double.Parse(textBox1.Text);
nu = '*';
textBox1.Text = null;
}

private void button16_Click(object sender, EventArgs e)
{
num = double.Parse(textBox1.Text);
nu = '/';
textBox1.Text = null;
}

private void button17_Click(object sender, EventArgs e)
{
if (textBox1.Text.Length > 0)
{
this.textBox1.Text = textBox1.Text.Substring(0, textBox1.Text.Length - 1);
}
}

private void button18_Click(object sender, EventArgs e)
{
textBox1.Text = " ";
}
private void textBox1_TextChanged(object sender, EventArgs e)
{

}
}
}
...全文
739 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
wanzi_1434761013 2014-07-01
  • 打赏
  • 举报
回复
计算器制作实例 private List<double> G_list_value = //记录累加数值 new List<double>(); private bool G_bl_add = false;//判断是否刚刚按下+号 private bool G_bl_value = false;//判断是否刚刚按下=号 private bool G_bl_key = false;//防止连续按+号 private void btn_clear_Click(object sender, EventArgs e) { G_list_value.Clear();//清空集合中数值 lb_express.Text = GetString();//清空计算表达式 txt_value.Clear();//清空累加结果 } private void btn_add_Click(object sender, EventArgs e) { if (G_bl_value)//判断是否刚刚按下=号 { G_bl_value = false;//设置刚刚按下的不是=号 G_bl_key = true;//设置刚刚按下的是加号 } else { if (!G_bl_key)//判断是否连续按+号 { G_list_value.Add(//向集合中添加累加的数值 double.Parse(txt_value.Text)); GetValue();//计算累加数值并输出CodeGo.net/ lb_express.Text = GetString();//得到数值的字符串表示 G_bl_add = true;//设置已经按下+号 G_bl_key = true;//防止多次按下+号 } } }
threenewbee 2014-06-28
  • 打赏
  • 举报
回复
整个代码都是错的。 自己下载代码看看应该怎么写 http://download.csdn.net/search?q=%E8%AE%A1%E7%AE%97%E5%99%A8%20C%23
gbk8290 2014-06-28
  • 打赏
  • 举报
回复
我也看不懂,程序逻辑有问题
zhouxiulu 2014-06-28
  • 打赏
  • 举报
回复
这个我感觉你理一下思路应该就可以出来了
yixian2007 2014-06-27
  • 打赏
  • 举报
回复
看不懂需求。
xdashewan 2014-06-26
  • 打赏
  • 举报
回复
拼接字符串,把数字和符号都当然做字符
tinydyw 2014-06-26
  • 打赏
  • 举报
回复
没看懂需求...另外你不判断除数为0么..
於黾 2014-06-26
  • 打赏
  • 举报
回复
什么叫把运算显示出来,运算是什么东西? 运算符?运算结果?运算过程? 显示到哪里?

111,093

社区成员

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

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

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