Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 在窗体外部单击时恢复焦点_Vb.net - Fatal编程技术网

Vb.net 在窗体外部单击时恢复焦点

Vb.net 在窗体外部单击时恢复焦点,vb.net,Vb.net,我写了一个程序,用遥控器控制音量。 它需要保持专注,否则它将不再接收命令。 为了恢复焦点,使用计时器,每秒检查一次窗体是否仍有焦点。 代码如下: Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick If Not Me.Focused Then Me.Activate() End If End Sub 只要我在VisualStudio中运行它,它就工作得非常完美

我写了一个程序,用遥控器控制音量。 它需要保持专注,否则它将不再接收命令。 为了恢复焦点,使用计时器,每秒检查一次窗体是否仍有焦点。 代码如下:

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    If Not Me.Focused Then
        Me.Activate()
    End If
End Sub
只要我在VisualStudio中运行它,它就工作得非常完美

当我关闭VisualStudio时,它不再恢复焦点。 我在另一台没有安装VisualStudio的计算机上运行了这个程序,它可以正常工作


有什么问题吗?

只要把它放在最上面:
Form.TopMost=True
TopMost已经设置好了。你的时间间隔是多少?TopMost已经设置好了。Topmost使它保持在顶端,但不保持专注。奇怪的是,我在3台装有相同版本windows 10 home的电脑上试用了它。其中两个安装了visual studio。在其中一个平台上,只要VisualStudio没有启动,它就可以正常工作。关闭visual studio没有帮助。另一方面,它只有在VisualStudio中使用start时才起作用。当visual studio关闭时,如果单击其他位置,焦点将丢失。间隔是1000,设置为5000没有什么区别。好吧,就是这样,不需要设置为1000或5000,设置为100