Results 1 to 21 of 21

Thread: [2005] Mousemove vs. DoubleClick - who will win?

  1. #1

    Thread Starter
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Location
    Ancient City, U.S.
    Posts
    1,254

    [2005] Mousemove vs. DoubleClick - who will win?

    It appears that mousemove wins, at least when I implement the following code:
    Code:
    Private Sub EitherListview_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lstFrom.MouseMove, lstTo.MouseMove
    
            Dim itmClick As Windows.Forms.ListViewItem
    
            'make sure the left mouse button is clicked
            'and that we have a listview to work with
            If e.Button = Windows.Forms.MouseButtons.Left Then
                If TypeOf sender Is Windows.Forms.ListView Then
                    With CType(sender, Windows.Forms.ListView)
    
                        'get the node here
                        itmClick = .GetItemAt(e.X, e.Y)
                        If Not itmClick Is Nothing Then
    
                            'allow a drag drop of this node
                            .DoDragDrop(itmClick, DragDropEffects.All)
    
                        End If
    
                    End With
                End If
            End If
    
        End Sub
    When this code is in effect, the double click event for the handled listview never gets raised. Does anybody know why?
    I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
    My war with a browser-redirect trojan

  2. #2
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2005] Mousemove vs. DoubleClick - who will win?

    where have you handled the Double Click event??
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  3. #3
    Frenzied Member
    Join Date
    Aug 2006
    Posts
    1,051

    Re: [2005] Mousemove vs. DoubleClick - who will win?

    It's possible, depending on what you are thinking, that the problem lies in the following line of code. What do you think this line of code is doing for you?

    Code:
    If Not itmClick Is Nothing Then
    Edit: Never mind. I did not read your post carefully enough.
    Last edited by FourBlades; Apr 3rd, 2008 at 09:25 PM.

  4. #4
    Frenzied Member
    Join Date
    Aug 2006
    Posts
    1,051

    Re: [2005] Mousemove vs. DoubleClick - who will win?

    Ok, well I get it.
    What's happening is that when the mouse enters the control the control begins to emit numerous mousemove events prior to any double click event being raised. So yes, the mousemove will always fire first.

  5. #5

    Thread Starter
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Location
    Ancient City, U.S.
    Posts
    1,254

    Re: [2005] Mousemove vs. DoubleClick - who will win?

    If you take out the code in the mousemove event, then the control will raise a double click event. So it isn't the handling of the mousemove event per se that cancels out the double click event, but something that I'm doing within the event that causes the double click event not to raise.

    It isn't a big deal, really. I either have drag and drop or I have double click ability. I'll probably just stick with drag and drop. Still, it seems to me there has to be a way around it, and it sounds like a good question for the brilliant minds on this forum.
    I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
    My war with a browser-redirect trojan

  6. #6
    Frenzied Member
    Join Date
    Aug 2006
    Posts
    1,051

    Re: [2005] Mousemove vs. DoubleClick - who will win?

    You can't stop an event from being "raised".
    If the control exists you can be sure that the event is being raised and also that it is not being "blocked".

    It is entirely possible though that:
    1) your own code is not properly registered to listen to the event
    2) the code you have within an event handler is not written to correctly do what you think it is supposed to do; and therefore you get the impression that the event is not raised.

    The object that raises the event will continue to function internally just as it was written to do. When the conditions occur that trigger that object's event the event will fire. That's certain.

  7. #7

    Thread Starter
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Location
    Ancient City, U.S.
    Posts
    1,254

    Re: [2005] Mousemove vs. DoubleClick - who will win?

    If you put a breakpoint at the beginning of the code for the double click event, and comment out the code in the mousemove event, the breakpoint in the double click event will be hit and the code will stop. If you uncomment the code in the mousemove event, the breakpoint in the double click event will not be hit.

    Try it yourself. Put my code into the mousemove event of a listview and then handle the double click event for the listview with something simple like a msgbox("hello"). You'll see.

    My guess is that something in the mousemove code is modifying conditions so that the double click event never fires.
    I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
    My war with a browser-redirect trojan

  8. #8
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: [2005] Mousemove vs. DoubleClick - who will win?

    I am a lot confused. In the mousemove event, which occurs anytime the cursor moves over the control, you check to see if the left button was clicked? BTW - If you hold the left button down and move the mouse the event fires numerous times.

    The control for the code appears to be a listview, but you check it anyway, and then you do whatever it is you are trying to do.

    Can you doubleclick the mouse and move the mouse at the same time? Think about it? The code I see is in the mousemove event.

    So, what are you trying to do? Drag and drop?
    Last edited by dbasnett; Apr 4th, 2008 at 12:57 PM.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  9. #9

    Thread Starter
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Location
    Ancient City, U.S.
    Posts
    1,254

    Re: [2005] Mousemove vs. DoubleClick - who will win?

    The code I use in the mousemove event was actually supplied to me by another developer, who had used it to handle mousemoves from multiple different types of controls. You're right - I could probably remove that 'typeof sender' check.

    The code - along with the corresponding dragover and dragdrop event code - works fine in implementing drag and drop. It's just that something in the drag code is causing the listview to not raise the double click event.

    It occurs to me that I probably should post the other two events' code as well. So here is the full thing:
    Code:
    Private Sub EitherListview_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lstFrom.MouseMove, lstTo.MouseMove
    
            Dim itmClick As Windows.Forms.ListViewItem
    
            'make sure the left mouse button is clicked
            'and that we have a listview to work with
            If e.Button = Windows.Forms.MouseButtons.Left Then
                If TypeOf sender Is Windows.Forms.ListView Then
                    With CType(sender, Windows.Forms.ListView)
    
                        'get the node here
                        itmClick = .GetItemAt(e.X, e.Y)
                        If Not itmClick Is Nothing Then
    
                            'allow a drag drop of this node
                            .DoDragDrop(itmClick, DragDropEffects.All)
    
                        End If
    
                    End With
                End If
            End If
    
        End Sub
    
        ''' <summary>
        ''' Responding to DragOver Events
        ''' </summary>
        Private Sub EitherListview_DragOver(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles lstFrom.DragOver, lstTo.DragOver
    
            'allow the dragover if it is from a listview on this form
            If e.Data.GetDataPresent(GetType(Windows.Forms.ListViewItem)) Then
    
                'get the item
                'and make sure it's from this form
                With CType(e.Data.GetData(GetType(Windows.Forms.ListViewItem)), Windows.Forms.ListViewItem)
                    If .ListView.FindForm Is Me.FindForm Then
    
                        'supported dragdrop
                        e.Effect = DragDropEffects.All
    
                        'also highlight the nearest node
                        'to show a context to the dragdrop event
                        If TypeOf sender Is Windows.Forms.ListView Then
                            With CType(sender, Windows.Forms.ListView)
    
                                Dim itmContext As Windows.Forms.ListViewItem
                                Dim pClient As Drawing.Point
    
                                pClient = .PointToClient(New Drawing.Point(e.X, e.Y))
                                itmContext = .GetItemAt(pClient.X, pClient.Y)
    
                                .SelectedItems.Clear()
                                If Not itmContext Is Nothing Then itmContext.Selected = True
    
                            End With
                        End If
    
                    Else
    
                        'not supported
                        e.Effect = DragDropEffects.None
    
                    End If
                End With
    
            Else
    
                'not supported
                e.Effect = DragDropEffects.None
    
            End If
    
        End Sub
    
        ''' <summary>
        ''' Responding to DragDrop Events
        ''' </summary>
        ''' <param name="sender"></param>
        ''' <param name="e"></param>
        ''' <remarks></remarks>
        Private Sub EitherListview_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles lstFrom.DragDrop, lstTo.DragDrop
    
            Dim lvwTarget As Windows.Forms.ListView
            Dim itmDrop As Windows.Forms.ListViewItem
            Dim itmContext As Windows.Forms.ListViewItem
            Dim pClient As Drawing.Point
    
    
            'make sure the dropped data is a listview item
            'and that we have a proper drop target
            If e.Data.GetDataPresent(GetType(Windows.Forms.ListViewItem)) Then
                If TypeOf sender Is Windows.Forms.ListView Then
    
                    'get the target listview
                    lvwTarget = sender
    
                    'get the dragged listviewitem
                    'and make sure it's from this form
                    itmDrop = e.Data.GetData(GetType(Windows.Forms.ListViewItem))
                    If itmDrop.ListView.FindForm Is Me.FindForm Then
    
                        'get the context item from the drop target, if any
                        pClient = lvwTarget.PointToClient(New Drawing.Point(e.X, e.Y))
                        itmContext = lvwTarget.GetItemAt(pClient.X, pClient.Y)
    
                        'see if we are dragging it onto the same listview, or another
                        If itmDrop.ListView Is sender Then
    
                            If itmContext Is itmDrop Then
                                'nothing to do; dropped onto self
                            ElseIf itmContext Is Nothing Then
                                'move to the end
                                itmDrop.ListView.Items.Remove(itmDrop)
                                lvwTarget.Items.Add(itmDrop)
                            Else
                                'move before selection
                                itmDrop.ListView.Items.Remove(itmDrop)
                                lvwTarget.Items.Insert(itmContext.Index, itmDrop)
                            End If
    
                        Else
    
                            'moving from one listview to another
                            itmDrop.ListView.Items.Remove(itmDrop)
                            If itmContext Is Nothing Then
                                lvwTarget.Items.Add(itmDrop)
                            Else
                                lvwTarget.Items.Insert(itmContext.Index, itmDrop)
                            End If
    
                        End If
    
                    End If
    
                End If
            End If
    
        End Sub
    I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
    My war with a browser-redirect trojan

  10. #10
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: [2005] Mousemove vs. DoubleClick - who will win?

    Let me try again. Why do you expect a double-click when the mouse is moving? Can you physically do it, move the mouse and doubleclick at the same time, and if you can, is that what this code does?

    And what, just a brief description, is the mousemove code supposed to do?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  11. #11

    Thread Starter
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Location
    Ancient City, U.S.
    Posts
    1,254

    Re: [2005] Mousemove vs. DoubleClick - who will win?

    I wanted the user to be able to move the selected listview item from one listview to another, and I wanted to allow a couple of different ways of doing it. One was to drag an item from one listview to another. The other was by double clicking an item in a listview. I can get either of the move ways working, but not both at the same time. If the drag and drop code is in place, then I can double click on an item all day long and the double click event simply won't raise. If the drag and drop code is removed, the double click event raises and I can move items just fine.

    Here's the double click code, just in case you are interested.
    Code:
    Private Sub lstFrom_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstFrom.DoubleClick
            ListViewTransfer(Me.lstFrom, Me.lstTo)
        End Sub
    
        Private Sub ListViewTransfer(ByRef FromListView As ListView, ByRef ToListView As ListView)
            For Each item As Windows.Forms.ListViewItem In FromListView.SelectedItems
                FromListView.Items.Remove(item)
                ToListView.Items.Add(item)
            Next
        End Sub
    Edit: Sorry, I should have explained this better up front rather than just jumping into the middle of the problem.
    I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
    My war with a browser-redirect trojan

  12. #12
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: [2005] Mousemove vs. DoubleClick - who will win?

    My guess is that you are interferring with the interpretation of the double click event. Basically, the time taken in working the mouse move event is making the two clicks of the double click appear too far apart. Not sure if that is even possible.

    Have you tried handling the click event, rather than the double click? I would try putting a listbox on the form and in the click event have a single line: Listbox1.Items.Add("Clicked Once") then run it and see what happens when you click once, and when you double click. If you just get two clicked once events, then you know what happened to your double click event.
    My usual boring signature: Nothing

  13. #13
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: [2005] Mousemove vs. DoubleClick - who will win?

    I created a listview and verified the double click(mouse-down,mouse-up,mouse-down, mouse-up) fires. it does.

    I also checked the mousemove event, and it appears normal also.

    I then tried mouse-down,mouse-up,mouse-down.
    Mousemove fired numerous times and when I finally did mouse-up the double click fired.

    add this to mousemove event handler

    dim recur as boolean = false

    Public MouseMove sub
    if recur then exit sub else recur = true
    .
    .
    .
    .
    .
    recur = false
    exit sub
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  14. #14

    Thread Starter
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Location
    Ancient City, U.S.
    Posts
    1,254

    Re: [2005] Mousemove vs. DoubleClick - who will win?

    You are almost right SH. I got just one 'clicked once', whether I clicked or double clicked, but if I took out the code in the mousemove event, I would get a 'clicked once' and a 'double click', as added by the listview's double click event. But with the mousemove code in there I never got 'double click'
    I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
    My war with a browser-redirect trojan

  15. #15
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: [2005] Mousemove vs. DoubleClick - who will win?

    well shucks. I said "I then tried mouse-down,mouse-up,mouse-down.
    Mousemove fired numerous times and when I finally did mouse-up the double click fired." This is only true if the mouse moves. If I

    mouse-down,mouse-up,mouse-down
    then wait without moving
    then mouse-up the doubleclick does not fire

    BUT

    double click = mouse-down,mouse-up,mouse-down, mouse-up

    the first part of the double-click is a MouseMove with LeftButton
    Last edited by dbasnett; Apr 4th, 2008 at 02:04 PM.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  16. #16
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: [2005] Mousemove vs. DoubleClick - who will win?

    Check this out

    Code:
        Private Sub ListView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.DoubleClick
            Debug.WriteLine("D " & Date.Now.ToLongTimeString)
        End Sub
        Private Sub ListView1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseMove
            Debug.WriteLine("MM " & Date.Now.ToLongTimeString)
            If e.Button = Windows.Forms.MouseButtons.Left Then
                Debug.WriteLine("L")
                For x = 0 To 500
                    Thread.Sleep(10)
                Next
            End If
        End Sub
    debug output
    MM 2:12:54 PM
    L
    MM 2:12:59 PM
    L
    D 2:13:04 PM

    It appears that mousemove with left button down fires twice, which makes sense.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  17. #17

    Thread Starter
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Location
    Ancient City, U.S.
    Posts
    1,254

    Re: [2005] Mousemove vs. DoubleClick - who will win?

    I can duplicate your results DB, as long as I don't have
    Code:
    .DoDragDrop(itmClick, DragDropEffects.All)
    in my mousemove event. If that's in place, then I can't get a double click.
    I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
    My war with a browser-redirect trojan

  18. #18
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: [2005] Mousemove vs. DoubleClick - who will win?

    Quote Originally Posted by dolot
    You are almost right SH. I got just one 'clicked once', whether I clicked or double clicked, but if I took out the code in the mousemove event, I would get a 'clicked once' and a 'double click', as added by the listview's double click event. But with the mousemove code in there I never got 'double click'
    Nope, I'd say from that that I was completely wrong. Interesting, though. Next thing to try is stripping out line after line to figure out which line causes the issue.
    My usual boring signature: Nothing

  19. #19
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: [2005] Mousemove vs. DoubleClick - who will win?

    Aren't we in the wrong event, MouseMove?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  20. #20

    Thread Starter
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Location
    Ancient City, U.S.
    Posts
    1,254

    Re: [2005] Mousemove vs. DoubleClick - who will win?

    Quote Originally Posted by Shaggy Hiker
    Next thing to try is stripping out line after line to figure out which line causes the issue.
    I tried that and it seems to be the following line in the mousemove event
    Code:
    .DoDragDrop(itmClick, DragDropEffects.All)
    When it's present, the double click event won't raise. If it's commented out, then the double click event raises
    I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
    My war with a browser-redirect trojan

  21. #21
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: [2005] Mousemove vs. DoubleClick - who will win?

    How about something like this

    Code:
        Dim itmClick As Windows.Forms.ListViewItem
        Dim stpW As New Stopwatch
        Const thresh As Integer = 200 'hmmm, what is good value
        Private Sub mDoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.DoubleClick
            Debug.WriteLine("D " & Date.Now.ToLongTimeString)
        End Sub
        Private Sub mMouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseDown
            stpW.Reset() : stpW.Start()
        End Sub
        Private Sub mMouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseUp
            Debug.WriteLine("MM " & Date.Now.ToLongTimeString & " " & stpW.ElapsedMilliseconds)
            If stpW.ElapsedMilliseconds < thresh Then Exit Sub
            With CType(sender, Windows.Forms.ListView)
                'get the node here
                itmClick = .GetItemAt(e.X, e.Y)
                If Not itmClick Is Nothing Then
                    'allow a drag drop of this node
                    .DoDragDrop(itmClick, DragDropEffects.Move)
                End If
            End With
        End Sub
    Last edited by dbasnett; Apr 4th, 2008 at 03:12 PM.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width