foreach (Control ctrl in this.Controls) // 所有的TextBox 或者 ComboBox为空
{
if (ctrl is TextBox || ctrl is ComboBox)
{
if (ctrl.Text == "")
{
MessageBox.Show("请输入完整信息。");
ctrl.Focus();
return;
}
}
}
ASCIIEncoding ascii = new ASCIIEncoding();//new ASCIIEncoding 的实例
byte[] bytestr = ascii.GetBytes(txtUserID.Text.Trim());
foreach (byte c in bytestr)//遍历这个数组里的内容
{
if (c < 48 || c > 57)//判断是否为数字
{
MessageBox.Show("请输入数字!");
txtUserID.Clear();
txtUserID.Focus();
return;
}
}
foreach (Control ctrl in this.Controls)
{
if(ctrl is TextBox){ ctrl.Text = ""; }
}