你可以这样
if(textBox[i].Leave!=null)
textBox[i].Leave+= new System.EventHandler(this.textBox_Leave);
if(textBox[i].Leave!=null)
textBox[i].Leave+= new System.EventHandler(this.textBox_Leave);
用一个bool来判断,在事件中加入:IsEanble=true;然后if (IsEanble)
//....就可以了
if(textBox[i].Leave==null)
textBox[i].Leave+= new System.EventHandler(this.textBox_Leave);
给你个参考
if(textBox[i].Leave == null)会出现以下编译错误------------------------------------------------------
E:\Code\C#\StatClass\ReportPanel.cs(373): 事件“System.Windows.Forms.Control.Leave”只能出现在 += 或 -= 的左边
private void Init()
{
for(int i = 0; i < textBox.Length; i++)
{
textBox[i].Leave-= new System.EventHandler(this.textBox_Leave);
textBox[i].Leave+= new System.EventHandler(this.textBox_Leave);
}
}