我怎么知道我的申请是否专注 [英] how can i know if my application is Focused or not
本文介绍了我怎么知道我的申请是否专注的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎么知道我的应用程序是否聚焦
how can i know if my application is Focused or not
推荐答案
你可以检查 ContainsFocus [ ^ ]。 (假设WinForms,因为你没有指明。如果你指的是WPF或ASPX或其他什么,答案可能会有所不同。)
You can check ContainsFocus[^] on all of your forms. (Assuming WinForms, because you didn''t specify. If you''re referring to WPF or ASPX or something else the answer may be different.)
除了正确的解决方案2 :
申请不能专注。
焦点总是意味着键盘焦点,当一个控件,每个交互式Windows会话一次只能一个,可以接受键盘的用户输入。您只能通过解决方案2告诉您确定当前关注的控件是应用程序窗口的所有者。作为窗口(窗体),它可以被激活或不被激活。当窗口被激活时,之前处于焦点的控件会自动获得焦点。
-SA
In addition to the correct Solution 2:
An application cannot be "focused" or not.
"Focus" always means keyboard focus, when a control, only one at a time per interactive Windows session, can accept user input from a keyboard. You can only determine is the control presently in focus is owner by on of the windows of your application, as Solution 2 tells you. As the the window (form), it can be activated or not. When a window is activated, the control which was previously in focus, automatically gains the focus.
—SA
使用主窗体的Activated和Deactivate事件...
这样的事情:
Use the Activated and Deactivate events of your main form...
Something like this:
Public Class MainForm
Private hasFocus As Boolean = False
Private Sub MainForm_Activated(sender As Object, e As EventArgs) Handles MyBase.Activated
hasFocus = True
End Sub
Private Sub MainForm_Deactivate(sender As Object, e As EventArgs) Handles MyBase.Deactivate
hasFocus = False
End Sub
End Class
祝你好运!
Good luck!
这篇关于我怎么知道我的申请是否专注的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文