做出来了.其实你已经做出一半来了.
还有你定义SUM的时候是DOUBLE类型.但输入数字却定义INT类型.这样不太好.类型应该一致.
代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication12
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int num1, num2;
int result;
try
{
num1 = Convert.ToInt32(textBox1.Text);
num2 = Convert.ToInt32(textBox2.Text);
result = Convert.ToInt32(num1+num2);
textBox3.Text = Convert.ToString(result);
}
catch (Exception ex)
{
MessageBox.Show("对不起,你的操作有误!错误为:"+ex.Message+"\n请输入数字类型!且不能为空!");
}
}
}
}