Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1169
  • Last Modified:

MouseMove event firing even when mouse not moving

If i hover my mouse over the DV object, and click the mouse button - this event fires.

Why? It should only fire when the mouse moves right? Why is it firing when i hover the mouse over the control, and then click the button without moving the mouse?

Im trying to get the drag and drop and double click functionality to co-exist but this is causing an issue with the double click event not firing properly with this code not working as expected.
Private Sub DV_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DV.MouseMove
        If e.Button = Windows.Forms.MouseButtons.Left Then
            'Once the drag operation starts, the mousemove no longer fires and is replaced by the DragOver event. This means we dont have to check whether there is a drag operation in progress first
            Debug.WriteLine("DragDrop")
            StartDragDrop()
        End If
    End Sub

Open in new window

0
tfsln
Asked:
tfsln
  • 5
  • 3
  • 2
  • +2
1 Solution
 
HalfAsleepCommented:
And you are sure you are not moving the mouse?  Do you get the click event also, or just the move event? Sometimes, it is easy to move the mouse as you are clicking it, but you should still get the click event, are you getting the click event?
Also, there are about 4 or 5 events custom made to support dragging operations. If you are trying to support drag and drop, you should have a look at them.
0
 
tfslnAuthor Commented:
I am not moving the mouse, that is a guarentee. The event is firing when you hover the mouse over, then click the button - the event seems to be triggered by the mouse click.

I am familiar with drag operations. You need an event to start the drag operation which is typically the mousedown event (but that wont work because it interferes with the double click event - and so this mousemove event is my backup plan, but that seems to have the same behaviour as the mousedown event which appears to me to be incorrect)
0
 
jpaulinoCommented:
If you want to implement a drag-drop you don't need that event. You have some specific for that!
Check this simple example
http://www.vb-helper.com/howto_net_drag_drop.html 
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
tfslnAuthor Commented:
What example uses the mousedown event. If you start a drag operation in the mousedown event, then the doubleclick event for that control stops working correctly.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
That's a good question...and I'm not sure why.  ...but I am able to get both DoubleClick and a "drag" to work at the same time though with the code below.  =\

I did notice that the even when the mouse is just sitting there I get "random" MouseMove events every 10 - 20 seconds.  I LITERALLY let go of the mouse and the number on the form increments by 2 every so often.  And no, the desk isn't vibrating or being bumped...no earthquakes or anything...  =)
Public Class Form1
 
    Private cnt As Integer
 
    Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
        cnt = cnt + 1
        Me.Text = "MouseMove: " & cnt
        If e.Button = Windows.Forms.MouseButtons.Left Then
            Me.DoDragDrop(Me, DragDropEffects.All)
        End If
    End Sub
 
    Private Sub Form1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.DoubleClick
        MessageBox.Show("DoubleClick")
    End Sub
 
End Class

Open in new window

0
 
omegaomegaDeveloperCommented:
Hello, tfsln,

You might also find the SystemInformation.DragSize Property to be helpful.  It won't prevent the spurious move events, but it may help in preventing the initiation of unwanted drag operations resulting from small mouse movements.

Cheers,
Randy
0
 
tfslnAuthor Commented:
So i would need to do something like record when the mouse was pressed down, and use the mousemove event to establish whether they have dragged the cursor outside the bounds of SystemInformation.DragSize?

That seems like alot of work. This would not be a problem if the MouseMove event was not raised when the mouse button is clicked. Isnt it frustrating when you hit a road block because one of the most fundamental basics in your coding environment has a bug in it? This is the kind of stuff i get from infragistics. Microsoft are usually pretty good.

SystemInformation.DragSize doesnt really help me, i mean, it just returns a Size object. It doesnt really make the solution any easier unless im missing something?
0
 
omegaomegaDeveloperCommented:
Hi, tfsln,

Re: "That seems like alot of work."

I suppose any work that "shouldn't" be required is always too much.  But really, I don't find this so hard.  I create a (module scope) "tolerance" rectangle in the MouseDown event (one instruction):

     mDragTolerance = New Rectangle(e.X - CInt(SystemInformation.DragSize.Width / 2), _
                                                       e.Y - CInt(SystemInformation.DragSize.Height / 2), _
                                                       SystemInformation.DragSize.Width, _
                                                       SystemInformation.DragSize.Height)

and then test the mouse location against it in the MouseMove event:

     If (Rectangle.op_Inequality(mdreDragTolerance, Rectangle.Empty) AndAlso _
                            Not mdreDragTolerance.Contains(e.X, e.Y)) Then
          ...

(two more instructions, if you include the terminating End If).   I do find it strange (and inconvenient) that it is only DragSize that is available and not a rectangle of that size.  (The documentation for DragSize even refers to a rectangle centred on the mouse position.)

Re: "Isnt it frustrating..."

Yep.  But I suppose that's why they pay us the big bucks.  ;-)

Re: "SystemInformation.DragSize doesnt really help me..."

You're right.  IdleMind's solution is (as usual) perfectly fine without it (and deserves full credit).  But using DragSize might make the drags that your application does a tiny bit more consistent with those performed by Windows itself.

Cheers,
Randy

0
 
tfslnAuthor Commented:
Ok thanks for that. I've never really needed to go into rectangles and drawing with the applications ive developed thus far. But using your example i think i know what to do now.

Idle_Mind's solution does not work for me because with the control i am using (an infragistics UltraDayView control) behaves even weirder.

Notice in Idle_Mind's example, the counter increases only when the mouse button is released. With the UltraDayView control, the mousemove is fired when the mouse button is pressed AND when its released.

Extremely annoying. Seriously i dont know about anyone else, but infragistics are the worst company ive ever dealt with in terms of bugs.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Never used any third party controls...  =\
0
 
omegaomegaDeveloperCommented:
Hello, tfsln,

I too avoid third party controls.  (I seem to recall getting into difficulties with them in some previous life.)  And I have no experience at all with infragistics controls.

This is just wild speculation, but I wonder if you could make any gains by creating your own control (maybe a UserControl) and then adding the infragistics control to it.  Then perhaps you could control whether or not MouseMove events were handled by your control, or passed on to the infragistics control for processing.  This way you might be able to get more normal MouseMove behaviour.

(And you were worried that DragSize was a lot of work... :-(  )

Cheers,
Randy
0
 
tfslnAuthor Commented:
Nah i think i have all the information i need from this question. I've actually posted another question about the MouseMove problem. I think ill try your suggestion though.

Thanks for your time
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

  • 5
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now