C# Winform 非空验证

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    }

 

posted @ 2018-10-19 21:57  洋三岁  阅读(2755)  评论(0编辑  收藏  举报
友情链接: 梦想农夫