我正在构建一个弹出式键盘。我使用sendkeys,所以我不希望表单/键盘成为焦点。此代码可防止:
Protected Overrides ReadOnly Property CreateParams() As System.Windows.Forms.CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.Style = cp.Style Or &H56000000
Return cp
End Get
然而,当我尝试移动表格/键盘时,它不会顺利移动。它会移动,但只有在你释放鼠标后才会移动。有没有办法,我可以同时拥有,没有焦点和顺利移动?
答案 0 :(得分:0)
我补充说:
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_MOVING Then
Dim r As RECT
r = DirectCast(Marshal.PtrToStructure(m.LParam, GetType(RECT)), RECT)
Me.Location = New Point(r.Left, r.Top)
End If
MyBase.WndProc(m)
End Sub
然后允许表单正确移动。
以下是所有代码:
Imports System.Runtime.InteropServices
Private Const WS_CHILD = &H40000000
Private Const WS_EX_NOACTIVATE = &H8000000
Private Const WM_MOVING = &H216
Private Structure RECT
Public Left As Integer
Public Top As Integer
Public Right As Integer
Public Bottom As Integer
End Structure
Protected Overrides ReadOnly Property CreateParams() As CreateParams
Get
Dim p As CreateParams = MyBase.CreateParams
p.Style = p.Style Or WS_CHILD
p.ExStyle = p.ExStyle Or WS_EX_NOACTIVATE
Return p
End Get
End Property
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_MOVING Then
Dim r As RECT
r = DirectCast(Marshal.PtrToStructure(m.LParam, GetType(RECT)), RECT)
Me.Location = New Point(r.Left, r.Top)
End If
MyBase.WndProc(m)
End Sub