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    }