winforms 使用(SendMessage)时,列表框没有双击事件

mec1mxoz  于 2023-06-24  发布在  其他
关注(0)|答案(1)|浏览(133)

我用这个代码来移动窗体。by(Handles Me.MouseDown,MyListBox.MouseDown)

Public Enum ResizeDirection
    None = 0
    Left = 1
    TopLeft = 2
    Top = 3
    TopRight = 4
    Right = 5
    BottomRight = 6
    Bottom = 7
    BottomLeft = 8
End Enum
Private _resizeDir As ResizeDirection = ResizeDirection.None
Private Const WM_NCLBUTTONDOWN As Integer = &HA1
Private Const HTBORDER As Integer = 18
Private Const HTBOTTOM As Integer = 15
Private Const HTBOTTOMLEFT As Integer = 16
Private Const HTBOTTOMRIGHT As Integer = 17
Private Const HTCAPTION As Integer = 2
Private Const HTLEFT As Integer = 10
Private Const HTRIGHT As Integer = 11
Private Const HTTOP As Integer = 12
Private Const HTTOPLEFT As Integer = 13
Private Const HTTOPRIGHT As Integer = 14
<System.Runtime.InteropServices.DllImport("user32.dll")>
Public Shared Function ReleaseCapture() As Boolean
End Function
<System.Runtime.InteropServices.DllImport("user32.dll")>
Public Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
End Function
Private Sub MoveForm()
    ReleaseCapture()
    SendMessage(Me.Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0)
End Sub
Private Sub FormMoveByListBox(sender As Object, e As MouseEventArgs) Handles Me.MouseDown, MyListBox.MouseDown
    If e.Button = MouseButtons.Left And Me.WindowState <> FormWindowState.Maximized Then
        MoveForm()
    End If
End Sub
  Private Sub MyListBox_DoubleClick(sender As Object, e As EventArgs) Handles MyListBox.DoubleClick
 'Not Work This Event. 
    End Sub

我想让事件与(SendMessage)vs2019-vb.net我的列表框没有双击事件。

zpqajqem

zpqajqem1#

有了这个代码,你既可以发送邮件,也可以双击

Private Sub FormMoveByListBox(sender As Object, e As MouseEventArgs) Handles Me.MouseDown, MyListBox.MouseDown
    If e.Button = MouseButtons.Left And Me.WindowState <> FormWindowState.Maximized Then
              If e.Clicks = 1 Then
            MoveForm()
        ElseIf e.Clicks = 2 Then
            Dim IFP = MyListBox.IndexFromPoint(e.Location)
            If IFP <> System.Windows.Forms.ListBox.NoMatches Then
              ' Handle double-click events
            End If
        End If
    End If
End Sub

相关问题