- 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 計算器
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- string a = textBox1.Text;
- string b = textBox2.Text;
- int i1, i2;
- if (!int.TryParse(a, out i1))
- {
- MessageBox.Show("第一個數格式錯誤,請重新輸入");
- return; //需要調出,不然會返回0,這個數。
- }
- if(int.TryParse(b,out i2)==false)
- {
- MessageBox.Show("第二個數格式錯誤,請重新輸入");
- return;
- }
- int i3 = i1 + i2;
- textBox3.Text = Convert.ToString(i3);//i3.ToString()
- }
- }
- }