1.遍歷控件方式進行驗證
1 public bool checkInpu() { 2 2 foreach (Control item in Controls)//遍歷控件 3 3 { 4 4 if (item is TextBox && item.Text == "")//遍歷TextBox類型控件 根據需求可以增加條件跳過某個控件不遍歷 5 5 { 6 6 item.Focus(); 7 7 MessageBox.Show("請輸入完善的信息!","信息",MessageBoxButtons.OKCancel,MessageBoxIcon.Information); 8 8 return false; 9 9 } 10 10 return true; 11 11 } 12 }