简体   繁体   中英

How to check current mouse position beyond my view area

I have found the following open source that is easy example about dragging and dropping controls in WPF. " http://www.codeproject.com/Articles/148503/Simple-Drag-Selection-in-WPF " With this source, I met the problems that when I move control, this moved control can move to outside of view area and disappear from this view. Until now, I'm still stuck in the root. Any one can help me to solve this problem? Thanks for your attention.

For you control override the PreviewMouseLeftButtonDown event and inside of this method get the mouse position coordinates relative to a screen.

Right after call the CaptureMouse(); for your control.

This will allow you to monitor the mouse move outside of your control, so make sure you override the PreviewMouseMove and inside of the PreviewMouseMove you should be able to make your calculations of whether the mouse is inside or outside of the control's area or any other areas you want to compare against.

In addition you will need to override the PreviewMouseUp and inside of it release the mouse capture ReleaseMouseCapture(); from the previous PreviewMouseLeftButtonDown call. This is important or you will end up with weirdly behaving mouse.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM