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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
bool plus;
bool minus;
bool multiply;
bool divide;
private void button0_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 buttonPlus_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
return;
else
{
plus = true;
textBox1.Text = textBox1.Text + " + ";
}
}
private void buttonDivide_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
return;
else
{
divide = true;
textBox1.Text = textBox1.Text + " / ";
}
}
private void buttonMinus_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
return;
else
{
minus = true;
textBox1.Text = textBox1.Text + " - ";
}
}
private void buttonMultiply_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
return;
else
{
multiply = true;
textBox1.Text = textBox1.Text + " * ";
}
}
private void buttonClear_Click(object sender, EventArgs e)
{
textBox1.Text = string.Empty;
}
private void buttonEquals_Click(object sender, EventArgs e)
{
if (plus)
{
}
if (minus)
{
}
if (multiply)
{
}
if (divide)
{
}
}
}
}
我坚持的部分是在我按下数学按钮(+、-、/、*)之后。我只想在文本框中显示一个字符,除非我按另一个数字。
示例:现在,这就是发生的事情:87 + + + + + + +
我想要 87 + 并且我想要它,如果用户添加另一个数字,我可以添加另一个,比如 87 + 87 + 等。
另外,在添加数学逻辑时,我需要一点指导。
我正在考虑以某种方式将字符串中的任何内容存储在变量中的数学符号之前,然后对进行数学符号的数字执行相同的操作。这很好还是有更简单/不太复杂的方法来完成这个?