简体   繁体   English

我们可以在请假事件中得到控制吗?

[英]Can we get control in leave event?

When i want to get an control, i can type like this (exp listview): 当我想获得一个控件时,我可以这样输入(exp listview):

ListView lst = (ListView)this.ActiveControl;

But in Leave event, I can't write like that. 但是在请假事件中,我不能这样写。
So can somebody help me how to get a control at Leave event? 那么有人可以帮我如何在请假事件中获得控制权吗? In Leave event it say that control is no longer active. 在离开事件中,它表示控件不再处于活动状态。 How can we get a control by the way above? 我们如何才能通过上述方式获得控制权?

Error occurs because when a control has lost the focus, then it is not active any more. 发生错误是因为当控件失去焦点时,它不再处于活动状态。 If you want to use your last active control, you can save it using Enter event and use it in Leave : 如果要使用上一个活动控件,则可以使用Enter事件保存它,并在Leave使用它:

Define a variable inside class: 在类内部定义一个变量:

Control ctlActive = null;

Inside Enter event: 内部Enter事件:

ctlActive = this.ActiveControl;
// OR:
ctlActive = sender as Control;

Inside Leave event: 内部请假事件:

if (ctlActive != null && ctlActive is ListView)
{
    var lst = ctlActive as ListView;
    // do something...
}
//...
ctlActive = null;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM