|
-
Apr 3rd, 2008, 03:43 PM
#1
Thread Starter
Frenzied Member
[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
-
Apr 3rd, 2008, 04:56 PM
#2
Re: [2005] Mousemove vs. DoubleClick - who will win?
where have you handled the Double Click event??
-
Apr 3rd, 2008, 09:22 PM
#3
Frenzied Member
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.
-
Apr 3rd, 2008, 09:28 PM
#4
Frenzied Member
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.
-
Apr 4th, 2008, 08:55 AM
#5
Thread Starter
Frenzied Member
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
-
Apr 4th, 2008, 11:49 AM
#6
Frenzied Member
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.
-
Apr 4th, 2008, 12:27 PM
#7
Thread Starter
Frenzied Member
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
-
Apr 4th, 2008, 12:52 PM
#8
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.
-
Apr 4th, 2008, 01:02 PM
#9
Thread Starter
Frenzied Member
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
-
Apr 4th, 2008, 01:08 PM
#10
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?
-
Apr 4th, 2008, 01:19 PM
#11
Thread Starter
Frenzied Member
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
-
Apr 4th, 2008, 01:28 PM
#12
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
 
-
Apr 4th, 2008, 01:38 PM
#13
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
-
Apr 4th, 2008, 01:47 PM
#14
Thread Starter
Frenzied Member
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
-
Apr 4th, 2008, 01:53 PM
#15
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.
-
Apr 4th, 2008, 02:14 PM
#16
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.
-
Apr 4th, 2008, 02:19 PM
#17
Thread Starter
Frenzied Member
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
-
Apr 4th, 2008, 02:19 PM
#18
Re: [2005] Mousemove vs. DoubleClick - who will win?
 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
 
-
Apr 4th, 2008, 02:29 PM
#19
Re: [2005] Mousemove vs. DoubleClick - who will win?
Aren't we in the wrong event, MouseMove?
-
Apr 4th, 2008, 02:47 PM
#20
Thread Starter
Frenzied Member
Re: [2005] Mousemove vs. DoubleClick - who will win?
 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
-
Apr 4th, 2008, 02:58 PM
#21
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|