WinForm 按鈕使用

Code:
  1.  using System;  
  2.   
  3. using System.Collections.Generic;  
  4. using System.ComponentModel;  
  5. using System.Data;  
  6. using System.Drawing;  
  7. using System.Linq;  
  8. using System.Text;  
  9. using System.Windows.Forms;  
  10.    
  11. namespace WinForm2  
  12. {  
  13.     public partial class Form1 : Form  
  14.     {  
  15.         public Form1()  
  16.         {  
  17.             InitializeComponent();  
  18.         }  
  19.    
  20.         private void button1_Click(object sender, EventArgs e)  
  21.         {  
  22.             string str1 = textBox1.Text;  
  23.             string str2 = textBox2.Text;  
  24.             int i1, i2;  
  25.             if (!int.TryParse(str1, out i1))  
  26.             {  
  27.                 MessageBox.Show("text1 is not a real number");  
  28.                 textBox1.Text = "";  
  29.                 textBox2.Text = "";  
  30.                 return;  
  31.             }  
  32.             if (int.TryParse(str2, out i2) == false)  
  33.             {  
  34.                 MessageBox.Show("text2 is not a real number");  
  35.                 textBox1.Text = "";  
  36.                 textBox2.Text = "";  
  37.                 return;  
  38.             }  
  39.               
  40.             int i3 = i1 + i2;  
  41.             textBox3.Text = Convert.ToString(i3);  
  42.         }  
  43.     }  
  44. }  
  45.    

 

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