【发布时间】:2017-07-20 09:37:26
【问题描述】:
概览
我在那里进行了研究,我知道有大量信息将多个事件处理程序订阅到单个事件,但是,我无法将其应用于我的场景。几乎我有大约 30 个来自 textBox 的 validation event 处理程序,它们都在执行相同的过程。以下是其中一个处理程序:
private void txt_HouseName_Validating(object sender, CancelEventArgs e)
{ // Convert User input to TitleCase After focus is lost.
if (Utillity.IsAllLetters(txt_HouseName.Text) | !string.IsNullOrEmpty(txt_HouseName.Text))
{
errorProvider.Clear();
txt_HouseName.Text = Utillity.ToTitle(txt_HouseName.Text);
isValid = true;
}
else
{
errorProvider.SetError(txt_HouseName, "InValid Input, please reType!!");
isValid = false;
//MessageBox.Show("Not Valid");
}
}
如何将我的代码最小化为这些代码行之一,并且只有其中一个事件处理程序? 我知道我应该在设计器代码中附加它们类似的东西
this.txt_Fax.Validating += new System.ComponentModel.CancelEventHandler(this.txt_Fax_Validating);
但是因为它们是 textboxes 我将如何将 1 validating events handlers 附加到我所有的 TextBoxes 上
【问题讨论】:
标签: c# winforms textbox event-handling