昨天查了msdn
窗体接收和失去当前焦点,应该使用 Activeated 和 Deactivated 事件
this.Activated += new System.EventHandler(this.Form1_Activated);
void Form1_Activated(object sender, System.EventArgs e)
{
//throw new System.Exception("The method or operation is not implemented.");
}
this.Deactivate += new System.EventHandler(this.Form1_Deactivate);
void Form1_Deactivate(object sender, System.EventArgs e)
{
//throw new System.Exception("The method or operation is not implemented.");
}
控件使用 Enter 和 Leave 这2个事件来处理输入焦点问题
this.nameTextBox.Enter += new System.EventHandler(this.nameTextBox_Enter);
private void nameTextBox_Enter(object sender, EventArgs e)
{
helpLabel.Text = "the Controller gets a focus";
}
this.nameTextBox.Leave += new System.EventHandler(this.nameTextBox_Leave);
private void nameTextBox_Leave(object sender, EventArgs e)
{
helpLabel.Text = "the Controller doesn't gets a focus";
}
msdn上无论 窗体 还是 控件 都有 GotFocus 和 LostFocus 事件,我也试过了
但书上说,控件或窗体通常不使用 GotFocus 和 LostFocus 这2个相关事件。
那么什么时候才使用,我还不清楚,只能等碰到的时候再补了,哪位大虾知道请指点!