【代码】控件是否为空/是否数字/清空

来源:互联网 发布:c语言基础知识txt下载 编辑:程序博客网 时间:2024/05/21 20:00
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 = ""; }}

0 0
原创粉丝点击