我在表单上有一些控件,我通过设计器为这些控件分配了Leave事件的函数,类似于以下内容:
textBox1.Leave += new System.EventHandler(f1);
textBox2.Leave += new System.EventHandler(f2);
textBox3.Leave += new System.EventHandler(f3);
这些函数对文本框进行一些验证。请注意,并不是所有的文本框都调用相同的委托。
现在我需要做的是,在需要时告诉它们“嘿,触发离开事件”。在我的情况下,我在开始某个地方调用此函数:
private void validateTextBoxes()
{
foreach (Control c in c.Controls)
{
TextBox tb = c as TextBox;
if (tb != null)
{
// Fire the tb.Leave event to check values
}
}
}
每个文本框都使用自己的代码进行验证。
Windows Forms
,验证已经完成。 - Nikola Markovinović