C#WPF DragMove没有Window_LocationChanged() [英] C# WPF DragMove without Window_LocationChanged()

查看:883
本文介绍了C#WPF DragMove没有Window_LocationChanged()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现了东西在Windows窗体类似于DragMove但设置为10个单位的主屏幕边缘的界限。

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

当切换到WPF,我发现< A HREF =http://stackoverflow.com/questions/568012/wpf-window-drag-move-boundary>这个线程要实现相同的结果是有用的。

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.

有一个简单的方法,以避免靠窗的给定区域以外的地方移动,而无需使用 LocationChanged 事件?我基本上要在它发生之前,限制窗口的移动

Is there a simple 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.

推荐答案

这本是非常很难用WPF实现的,因为它不公开基本Win32函数和事件类似的WinForms一样。我曾在那里我需要调整窗口大小的一个项目,我不得不使用的PInvoke SetWindowPos为此在一个正常的方式。

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可以帮助你,但是这仍是相当困难的。请参见 HTTP:// WWW。 wpfmentor.com/2009/01/how-to-get-hwnd-and-hook-into-wndproc.html 并的 http://msdn.microsoft.com/en-us/library/system.windows.interop.hwndsource.addhook.aspx 了解更多信息。

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.

这篇关于C#WPF DragMove没有Window_LocationChanged()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆