c# textBox 输入校验

窗体上有很多控件,用来设置一些参数,需要在点击OK时对所有的参数进行验证,如果有参数无效则显示错误信息,效果如下:


为控件添加验证事件:

private void textBox1_Validated(object sender, EventArgs e)  
        {  
  
            if (string.IsNullOrEmpty(textBox1.Text))  
                errorProvider1.SetError(textBox1, "invalid textbox value, could not be null");  
            else  
                errorProvider1.SetError(textBox1, string.Empty);  
        }  


猜你喜欢

转载自blog.csdn.net/selaginella/article/details/79288672