VB.NET检查窗体是否聚焦
我似乎在任何地方都找不到这个看似简单的问题的答案: 我想检测窗体/窗口是否聚焦,这样我只能在未聚焦时闪烁窗口,以下是代码位:VB.NET检查窗体是否聚焦,vb.net,focus,Vb.net,Focus,我似乎在任何地方都找不到这个看似简单的问题的答案: 我想检测窗体/窗口是否聚焦,这样我只能在未聚焦时闪烁窗口,以下是代码位: If Me.Focused = False Then ' Doesn't work D: please fix Dim flash As New FLASHWINFO flash.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(flash) '/// size of structure in b
If Me.Focused = False Then ' Doesn't work D: please fix
Dim flash As New FLASHWINFO
flash.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(flash) '/// size of structure in bytes
flash.hwnd = MyBase.Handle '/// Handle to the window to be flashed
flash.dwFlags = FLASHW_ALL '/// to flash both the caption bar + the tray
flash.uCount = 5 '/// the number of flashes
flash.dwTimeout = 1000 '/// speed of flashes in MilliSeconds ( can be left out )
'/// flash the window you have specified the handle for...
FlashWindowEx(flash)
End If
有没有一个简单的方法来实现这一点?可能与答案2重复?即使答案不是VB.NET而是C#,那也不会有真正的区别。如果你是VB新手,甚至没有遇到C#是的,请阅读答案。答案#1与语言无关。答案#2向您展示了一个现成的VB.NET解决方案。那么你的问题在哪里呢?这不是我想要的,而是我;我已经把它写进了我的代码;P如果调用此函数,则使用设置为false的变量,然后在重新建立焦点时设置为true。:)这样异步后台工作人员就可以判断是否集中
Private Sub Form1_LostFocus(sender As Object, e As System.EventArgs) Handles Me.LostFocus
Dim flash As New FLASHWINFO
flash.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(flash) '/// size of structure in bytes
flash.hwnd = MyBase.Handle '/// Handle to the window to be flashed
flash.dwFlags = FLASHW_ALL '/// to flash both the caption bar + the tray
flash.uCount = 5 '/// the number of flashes
flash.dwTimeout = 1000 '/// speed of flashes in MilliSeconds ( can be left out )
'/// flash the window you have specified the handle for...
FlashWindowEx(flash)
End Sub