Search code examples
wpfwindowmouseevent

Custom window moving code. How to deal with rapid mouse movements?


I've created my own code for moving windows around, using the following system:

  • mousedown (in a certain area) activates the move

  • track mousemove events to move window with cursor

  • mouseup event completes the move

This works great except in cases where the mouse is moved so fast that the cursor leaves my window, before firing a mousemove event, thus not giving me a chance to move the window in the direction the cursor is moving.

Any solutions to this?


Solution

  • The method you are after is Mouse.Capture.

    This answer has some more details on use within WPF.