[英]Error in windows form calculator for 2 values only
錯誤出現在 num1+float.Parse(textBox1.text); 我正在開發一個計算器,每當我單擊數字然后單擊任何運算符時,程序都會停止說輸入字符串的格式不正確。 我沒有在計算器中創建任何相等的運算符,所以當我在單擊運算符后單擊另一個值時,它會在 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();
}
您已清除文本框。
顯然,您的文本框中沒有任何要添加的內容。
如果要增加文本框值,請先將該值存儲在臨時變量中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.