开发者

C# WPF DragMove without Window_LocationChanged()

开发者 https://www.devze.com 2023-01-20 22:41 出处:网络
I implemented something in Windows Forms similar to DragMove but with boundaries set to 10 units of the margins of the primary screen.

I implemented something in Windows Forms similar to DragMove but with boundaries set to 10 units of the margins of the primary screen.

When switching over to WPF I found this thread to be useful in achieving the same result.

However, since this is a post-move event, what happens is that if my window is dragged beyond the boundaries I set, it "jumps" back. I would like to avoid this effect as it looks terrible.

Is there a simple开发者_StackOverflow社区 way to avoid the window to be moved outside a given area without using the LocationChanged event? I basically want to restrict the movement of the window before it happens.


These this are very hard to achieve with WPF because it does not expose the base Win32 functions and events like WinForms did. I had a project where I needed to to resize a window and I had to use PInvoke SetWindowPos to do this in a normal manner.

AddHook may help you, but this will still be quite difficult. See http://www.wpfmentor.com/2009/01/how-to-get-hwnd-and-hook-into-wndproc.html and http://msdn.microsoft.com/en-us/library/system.windows.interop.hwndsource.addhook.aspx for more information.

0

精彩评论

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