C# WPF DragMove 不带 Window_LocationChanged()

发布于 2024-09-28 06:24:35 字数 353 浏览 0 评论 0原文

我在 Windows 窗体中实现了类似于 DragMove 的功能,但边界设置为主屏幕边距的 10 个单位。

当切换到 WPF 时,我发现此线程对于实现相同的结果很有用。

但是,由于这是一个移动后事件,因此如果我的窗口被拖动到我设置的边界之外,它就会“跳”回来。我想避免这种效果,因为它看起来很糟糕。

有没有一种简单的方法可以避免窗口在不使用 LocationChanged 事件的情况下移动到给定区域之外?我基本上想在发生之前限制窗口的移动。

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 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怪我鬧 2024-10-05 06:24:35

这些使用 WPF 很难实现,因为它不像 WinForms 那样公开基本的 Win32 函数和事件。我有一个项目需要调整窗口大小,并且必须使用 PInvoke SetWindowPos 以正常方式执行此操作。

AddHook 可能会帮助你,但这仍然会很困难。请参阅 http://www. wpfmentor.com/2009/01/how-to-get-hwnd-and-hook-into-wndproc.htmlhttp://msdn.microsoft.com/en-us/library/system.windows.interop.hwndsource.addhook.aspx了解更多信息。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文