简体   繁体   English

Windows 窗体计算器中的错误仅适用于 2 个值

[英]Error in windows form calculator for 2 values only

Error is coming in num1+float.Parse(textBox1.text);错误出现在 num1+float.Parse(textBox1.text); I am developing a calculator and whenever i click on number and then click on any operator the program stops saying input string was not in a correct format.我正在开发一个计算器,每当我单击数字然后单击任何运算符时,程序都会停止说输入字符串的格式不正确。 I did not make any equal operator in calculator so when i will click on another value after clicking on operator it will show me the result in textox.我没有在计算器中创建任何相等的运算符,所以当我在单击运算符后单击另一个值时,它会在 textox 中显示结果。

private void buttonAdd_Click(object sender, EventArgs e)
    {
        num1 = float.Parse(textBox1.Text);
        textBox1.Clear();
        textBox1.Focus();

        ans = num1 + float.Parse(textBox1.Text);
        textBox1.Text = ans.ToString();
    }

You have cleared the text box.您已清除文本框。

Obviously you do not have anything in your textbox to add.显然,您的文本框中没有任何要添加的内容。

If you want increment, the textbox value, store the value in a temporary variable first.如果要增加文本框值,请先将该值存储在临时变量中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM