- windows form 加法运算
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace 练习1求和
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- string str1 = textBox1.Text;
- string str2 = textBox2.Text;
- int i1, i2;
- if (!int.TryParse(str1, out i1))
- {
- MessageBox.Show("第一个数不是合法整数");
- return;
- }
- if (!int.TryParse(str2, out i2))
- {
- MessageBox.Show("第二个数不是合法整数");
- return;
- }
- int i3 = i1 + i2;
- textBox3.Text = Convert.ToString(i3);
- }
- }
- }
复制代码 |