Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在计算器中覆盖?_C#_Calculator - Fatal编程技术网

C# 如何在计算器中覆盖?

C# 如何在计算器中覆盖?,c#,calculator,C#,Calculator,这是我用SharpDevelop编写的计算器代码。我需要知道如何覆盖一个数字 在我的代码中,当我发送第一个号码时,按下“添加”按钮后,文本框被清除 public partial class MainForm : Form { public MainForm() { InitializeComponent(); } double total1 = 0; double total2 = 0; void BtnOneClick(Object sender, Even

这是我用SharpDevelop编写的计算器代码。我需要知道如何覆盖一个数字

在我的代码中,当我发送第一个号码时,按下“添加”按钮后,文本框被清除

public partial class MainForm : Form
{
  public MainForm()
  {
    InitializeComponent();
  }

  double total1 = 0;
  double total2 = 0;

  void BtnOneClick(Object sender, EventArgs e)
  {
    txtDisplay.Text = txtDisplay.Text + btnOne.Text;
  }

  void BtnTwoClick(object sender, EventArgs e)
  {
    txtDisplay.Text = txtDisplay.Text + btnTwo.Text;
  }

  ...

  void BtnZeroClick(object sender, EventArgs e)
  {
    txtDisplay.Text = txtDisplay.Text + btnZero.Text;           
  }

  void BtnClearClick(object sender, EventArgs e)
  {
    txtDisplay.Clear();
  }

  void BtnPlusClick(object sender, EventArgs e)
  {
    total1 += double.Parse(txtDisplay.Text);
    txtDisplay.Clear();

    plusButtonClicked = true;
    minusButtonClicked = false;
    multiplyButtonClicked = false;
    divideButtonClicked = false;
  }

  ...

  bool plusButtonClicked = false;
  bool minusButtonClicked = false;
  bool multiplyButtonClicked = false;
  bool divideButtonClicked = false;
}
我想你想要

void BtnPlusClick(object sender, EventArgs e)
{
total1 += double.Parse(txtDisplay.Text);
txtDisplay.Text = total1.toString();
编辑:
。清除
将从文本框中删除文本。。我认为如果你想让其他事情发生,那么你需要重新思考你正在尝试做什么

Edit2如果这不是你想要的,我不知道是什么

    int total = 0;
    bool newNum = true;
    //1
    private void button1_Click(object sender, EventArgs e)
    {

        textBox1.Text = newNum ? "1" : textBox1.Text + "1";
        newNum = false;
    }
    //Add
    private void button2_Click(object sender, EventArgs e)
    {
        newNum = true;
        total += int.Parse(textBox1.Text);
        textBox1.Clear();
    }
    //Equals
    private void button3_Click(object sender, EventArgs e)
    {
        textBox1.Text = total.ToString();
    }

这是因为这条线: txtDisplay.Clear(); 用你的方法 btnpluclick()

如果您只想在开始提供下一个数字时清除它-只需更改bool标志(plusButtonClicked等)-如果其中的on设置为true,则进行
txtDisplay.Clear()

不知道你在问什么。。。也许您不应该在
btnpluclick
方法中调用
txtDisplay.Clear()
,因为
void btnpluclick(objectsender,EventArgs e){total1+=double.Parse(txtDisplay.Text);txtDisplay.Clear();
如果我删除txtDisplay.Clear()第二个数字将添加到第一个数字的旁边。在添加第二个数字之前,您将清除文本框。是否有可能您正在查找的是
total1=double.Parse(txtDisplay.Text);
,以便total1现在等于文本框中的数字,而不是先前添加到文本框中的total1?