Solved

MouseMove event firing even when mouse not moving

Posted on 2009-04-05
12
898 Views
Last Modified: 2013-11-26
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
Comment
Question by:tfsln
  • 5
  • 3
  • 2
  • +2
12 Comments
 
LVL 7

Expert Comment

by:HalfAsleep
ID: 24073227
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
 

Author Comment

by:tfsln
ID: 24073244
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
 
LVL 48

Expert Comment

by:jpaulino
ID: 24073416
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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:tfsln
ID: 24073422
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
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 24073547
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
 
LVL 12

Expert Comment

by:omegaomega
ID: 24079324
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
 

Author Comment

by:tfsln
ID: 24081975
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
 
LVL 12

Accepted Solution

by:
omegaomega earned 500 total points
ID: 24083397
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
 

Author Comment

by:tfsln
ID: 24083565
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
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 24083708
Never used any third party controls...  =\
0
 
LVL 12

Expert Comment

by:omegaomega
ID: 24083839
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
 

Author Comment

by:tfsln
ID: 24083848
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question