您的位置:首页 > 其它

winform程序之加法计算器(简单)

2010-12-16 16:53 323 查看


按上图布局,

结果的事件:

int i1, i2;
if (int.TryParse(textBox1.Text, out i1) == false)
{
MessageBox.Show("第一个数含非法数字");
textBox1.Focus();
textBox1.BackColor = Color.Red;
return;
}
if (int.TryParse(textBox2.Text, out i2) == false)
{
MessageBox.Show("第二个数含非法数字");
textBox2.Focus();
textBox2.BackColor = Color.Red;
return;
}
textBox1.BackColor = Color.White;
textBox2.BackColor = Color.White;
textBox3.Text = (i1 + i2).ToString();

/*
int i1 = 0;
int i2 = 0;
try
{
i1 = Convert.ToInt32(textBox1.Text);
}
catch
{
MessageBox.Show("第一个数为非法的整数!");
label3.Text = "请重新输入第一个数";
textBox1.Focus();
textBox1.BackColor = Color.Red;
return;
}
try
{
i2 = Convert.ToInt32(textBox2.Text);
}
catch
{
MessageBox.Show("第二个数为非法的数");
label3.Text = "请重新输入第二个数";
textBox2.Focus();
textBox2.BackColor = Color.Red;
return;
}
int i3 = i1 + i2;
textBox1.BackColor = Color.White;
textBox2.BackColor = Color.White;
textBox3.Text = i3.ToString();
*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐