开发者

WPF: Check mouse movement and cursor position within mouseleftbuttondown handler

I'm working on restoring the aero snap functionality in my wpf c# app which was lost when setting the resize to none. I have a rectangle at the top of my window of which I add code to its mouseleftbuttondown event.

I want to check whether the mouse has moved when the rectangle is being clicked so I can then de-maximize the window using code开发者_StackOverflow中文版.

The second part of my question is how can I track whether the cursor is at the top, left or right side of the screen so I can run code for the window to maximize or to align left or right of the screen like aero snap.

Thanks,


For your first issue, I believe you have to do it the other way around. That is, have a MouseMove handler to check if the left mouse button is down then to do what you need. You should preview the left mouse button to track if and where it was clicked in the first place.

Look for drag and drop tutorials and see how they initiate the drags for inspiration.


For your second issue, you can use PointToScreen() along with Mouse.GetPosition() to get the current position relative to the screen. Then use this to compare against the actual screen bounds with the SystemParameters.PrimaryScreenWidth and SystemParameters.PrimaryScreenHeight properties.

var pos = this.PointToScreen(Mouse.GetPosition(this)); //position relative to screen
if (pos.X == 0) //on the left
    //...
else if (pos.X == SystemParameters.PrimaryScreenWidth-1) //on the right (goes from 0 to (width-1))
    //...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜