Why MouseMove event occurs after MouseUp event?

If your mouse had previously been focused on a separate window, then clicking on a new window and shifting the focus of the mouse will generate a mouse move event (even if the mouse didn't move immediately before or after you clicked your mouse).

Here is a link to a similar StackOverflow response "Ghost" MouseMove Event


This is the intended behavior and will also be trigger whenever app is being switched (Eg: Alt+Tab).

You should go with workaround as suggested by @VishnuBabu's workaround. And to ignore initial mousemove trigger, you can get the current position of cursor once window is loaded instead of setting the LastLocation to Empty.


This is because the mouse capture by the MouseDown is released on MouseUp. And this extra MouseMove may be to ensure the cursor position. As a workaround you can do this

        Point LastLocation = Point.Empty;

        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            Debug.WriteLine("=> Form1_MouseDown, Clicks: " + e.Location + ", Location: " + e.Location + "");
        }

        private void Form1_MouseUp(object sender, MouseEventArgs e)
        {
            Debug.WriteLine("=> Form1_MouseUp, Clicks: " + e.Location + ", Location: " + e.Location + "");

        }

        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            if (LastLocation != e.Location)
            {
                LastLocation = e.Location;
                Debug.WriteLine("=> Form1_MouseMove, Clicks: " + e.Location + ", Location: " + e.Location + "");
            }
        }