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

Mansour_Dalir 2,036 Reputation points
2023-06-09T07:26:54.86+00:00

dou

hi I use this code to move the form. by (Handles Me.MouseDown, MyListBox.MouseDown) .

vs2019-vb.net My listbox does not have the double click event.

If there is another way to move the form (with FormBorderStyle=None),(that my box list is the reason for its transfer.) please provide it. Thanks.

    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

Developer technologies VB
0 comments No comments
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 34,221 Reputation points Microsoft External Staff
    2023-06-09T08:05:20.7866667+00:00

    Hi @Mansour_Dalir ,

    You are releasing the mouse capture in the MouseDown event handler, the doubleclick event cannot be fired normally.

    You might consider using the e.clicks in MouseDown event handle to determine whether a click or a double-click is triggered

        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
                    ' Handle double-click events
                End If
            End If
        End Sub
    

    Best Regards.

    Jiachen Li


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.