C#验证多个文本框? [英] C# validating multiple textboxes?

查看:172
本文介绍了C#验证多个文本框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我几乎20文本框和检查所有我需要调用验证事件的每使用errorprovider 20倍。难道还有比其它任何有效的方式。


解决方案

  this.textBox1.Validating + =新System.ComponentModel.CancelEventHandler(this.textBox_Validating); 
this.textBox2.Validating + =新System.ComponentModel.CancelEventHandler(this.textBox_Validating);
this.textBox3.Validating + =新System.ComponentModel.CancelEventHandler(this.textBox_Validating);

//等了20箱。
私人无效textBox_Validating(对象发件人,发送CancelEventArgs E)
{
文本框的文本框=(文本框)发送;

//什么就做什么哟必要在这里做的文本框。
}


I have almost 20 textboxes and to check all i have to call validate event 20 times each using errorprovider. Is there any efficient way other than that.

解决方案

this.textBox1.Validating += new System.ComponentModel.CancelEventHandler(this.textBox_Validating);
this.textBox2.Validating += new System.ComponentModel.CancelEventHandler(this.textBox_Validating);
this.textBox3.Validating += new System.ComponentModel.CancelEventHandler(this.textBox_Validating);

// And so on for the 20 boxes.
private void textBox_Validating(object sender, CancelEventArgs e)
{
    TextBox textbox = (TextBox)sender;

    // Do whatever yo need to do with textbox here.
}

这篇关于C#验证多个文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆