winform 组件简单遍历判断

foreach (Control item in this.Controls)
{
if (item is TextBox)
{
if (item.Text.Length <= 0)
{
TextBox t = (TextBox)item;
t.Focus();
t.BackColor = Color.Red;
MessageBox.Show("该项不能为空!");
return;
}

}
}

posted @ 2017-09-08 15:25  刀小爱  阅读(144)  评论(0)    收藏  举报