namespace Exer3
{
public partial class MyCalculator : Form
{
public MyCalculator()
{
InitializeComponent();
}
private void btnAdd_Click(object sender, EventArgs e)
{
int num1 = Convert.ToInt32(txtNum1.Text);
int num2 = Convert.ToInt32(txtNum2.Text);
if (txtNum1.Text.Length == 0 & txtNum2.Text.Length == 0)
{
MessageBox.Show("No Input Detected");
txtNum1.Focus();
txtNum2.Focus();
}
else
lblTotal.Text = (num1 + num2).ToString();
}
}
}
当我运行该程序,它计算得很好..但是当我试图离开文本框为空,然后单击添加按钮时,消息框将出现“未检测到输入”后程序将开始调试,并显示“输入字符串格式不正确”。请帮忙解决这个问题输入字符串格式不正确
任何问题吗?此外,请确保你输入的数字文本框 –
这将有助于很多,如果你想多一些问题的描述。标题是什么,当你试图编译它,或者运行它,或者究竟是什么? –
你的问题是什么? – mipe34