checked
{
try
{
TextBox3.Text = double.Parse(textBox1.Text)+double.Parse(textBox2.Text);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void button1_Click(object sender, EventArgs e)
{
int sum= Convert.ToInt32(textBox1.Text) + Convert.ToInt32(textBox2.Text);
textBox3.Text = sum.ToString();
}
private void button1_Click(object sender, EventArgs e)
{
int add = int.Parse(textBox1.Text) + int.Parse(textBox2.Text);
textBox3.Text = add.ToString();
}
创建个winform程序
从设计视图的工具箱中拖拽3个TextBox和1个Button
双击Button,进入Button的Click事件,写代码:
try
{
TextBox3.Text = (int.Parse(textBox1.Text)+int.Parse(textBox2.Text)).ToString();
}
catch
{
MessageBox.Show("输入的数字格式不正确");
}