检测被置于后台的应用程序 [英] Detecting an application being put in the background

查看:116
本文介绍了检测被置于后台的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够在其他一些应用程序排在最前面时进行一些GUI操作(通过alt标签,在外部窗口中单击,在任务栏中单击等).如何检测到我的应用程序刚刚离开了?

那时我想要的活动涉及显示/隐藏多个窗口,并且我不想使用OnDeactivate覆盖,因为如果我隐藏在停用"上并在激活"上显示,那么如果用户从一个应用程序窗口移到另一个应用程序窗口,我会闪烁.

激活"部分很好.每当主窗口收到OnActivated时,我就会显示我的子窗口.

如果有一个Application.OnActivate(...)/OnDeactivate(...)对,我就不会在这里发布.我可以只监听Application.OnDeactivate()并隐藏我的子窗口,并在触发Application.OnActivate()时恢复其可见性.

I''d like to be able to do some GUI manipulations when some other application goes to the front (by alt-tabbing, clicking in a foreign window, clicking in the task bar, etc). How do I detect that my application has just been navigated away from?

My desired activity at that point involves showing/hiding multiple windows and I don''t want to use the OnDeactivate override because if I hide on Deactivate and show on Activate, I get a flicker if the user is moving from one application window to another.

The "Activation" part is fine. I show my subwindows whenever a main window receives an OnActivated.

If there were an Application.OnActivate(...) / OnDeactivate(...) pair, I wouldn''t be posting here. I could just listen in on the Application.OnDeactivate() and hide my child windows, and restore their visibility when Application.OnActivate() would get triggered.

推荐答案


我还没有仔细考虑过,但是可以结合使用Deactivate事件和Form.ActiveForm属性.

Hi,
I haven''t thought this through in any detail but can you use a combination of the Deactivate event and the Form.ActiveForm property.

private void AnyForm_Deactivate(object sender, EventArgs e) {
  if (this.ActiveForm == null) {
    // no active forms
  }
}




艾伦.




Alan.


这篇关于检测被置于后台的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆