WinForm 練習1

  1. using System; 
  2. using System.Collections.Generic; 
  3. using System.ComponentModel; 
  4. using System.Data; 
  5. using System.Drawing; 
  6. using System.Linq; 
  7. using System.Text; 
  8. using System.Windows.Forms; 
  9.  
  10. namespace 計算器 
  11.     public partial class Form1 : Form 
  12.     { 
  13.         public Form1() 
  14.         { 
  15.             InitializeComponent(); 
  16.         } 
  17.  
  18.         private void button1_Click(object sender, EventArgs e) 
  19.         { 
  20.             string a = textBox1.Text; 
  21.             string b = textBox2.Text; 
  22.             int i1, i2; 
  23.             if (!int.TryParse(a, out i1)) 
  24.             { 
  25.                 MessageBox.Show("第一個數格式錯誤,請重新輸入"); 
  26.                 return;  //需要調出
  27.             } 
  28.             if(int.TryParse(b,out i2)==false
  29.             { 
  30.                 MessageBox.Show("第二個數格式錯誤,請重新輸入"); 
  31.                 return
  32.             } 
  33.             int i3 = i1 + i2; 
  34.             textBox3.Text = Convert.ToString(i3);//i3.ToString() 
  35.         } 
  36.     } 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章