关于窗体和控件获取与失去输入焦点的事件

昨天查了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个相关事件。

那么什么时候才使用,我还不清楚,只能等碰到的时候再补了,哪位大虾知道请指点!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值