Listbox does not have the double click event When (SendMessage) is used

91 Views Asked by At

I use this code to move the form. 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

I want to have the event with (SendMessage) vs2019-vb.net My listbox does not have the double click event.

1

There are 1 best solutions below

0
Mansour Dalir On

With this code, you have both Send Messenge and double click

 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