Mouse movement capture

前端 未结 3 534
时光取名叫无心
时光取名叫无心 2021-01-16 10:54

I have an application wich open a modal form with the ShowDialog method. Once this form is displayed I want to capture the mouse movement even if the cursor is outside the f

3条回答
  •  说谎
    说谎 (楼主)
    2021-01-16 11:09

    The Capture property is the correct way, but there are some limitations.

    • Only the foreground window can capture the mouse
    • Mouse capturing can be disabled by other parts of the system
    • The Win32 API function SetCapture gets reset everytime a "mouse up" event occours. I assume that also applies for .NET.

    See the remarks section of Capture property.

    When the mouse is captured, you'll receive the usual events but with a wider mouse coordinate range (for example a negative X position, if the mouse is left of the capturing control)

    Mouse capturing is fragile, because of it's global nature. Check if there are other ways to handle certain events. Perhaps the MouseLeave or MouseEnter events are enough in your case.

提交回复
热议问题