如何在WPF窗口外禁用鼠标? [英] How to disable mouse down outside WPF Window?

查看:259
本文介绍了如何在WPF窗口外禁用鼠标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在没有平台调用的情况下在WPF窗口外禁用鼠标?

在WPF窗口外按鼠标时我不想回复。

有可能吗?



>为什么?

我有一个小窗口,用户按下鼠标创建一个圆圈然后他移动鼠标向上移出窗口以增加圆的大小,最后当他喜欢这个大小,他再次按下鼠标以保存大小,但它已经在窗外,我通过鼠标捕获保留它,我不想得到除我的应用程序以外的其他响应。



你说我不能禁用它,我得到它,因为我无法实现我上面描述的。



但我认为我可以创造一个非常小的不透明的窗口(因为透明窗口允许鼠标自己工作),使其样式无,并保持窗口最多和激活在鼠标位置移动它鼠标位置,它可能工作,但我从来没有检查过,它不是一个专业方式。

解决方案

问题没有意义:鼠标按下是用户使用物理鼠标设备执行的操作,无法禁用。如果您可以禁用将鼠标指针移动到屏幕的任何区域,将极大地损害整个系统的可用性很难发明更多刺激性的系统滥用。



然而,如果你真的想要,你可以通过一些捕获鼠标UI元素,用于将所有软件鼠标事件分派给此元素。请参阅:

https://msdn.microsoft.com/en-us/library/system.windows.uielement.capturemouse%28v=vs.110%29.aspx [ ^ ],

https:/ /msdn.microsoft.com/en-us/library/system.windows.input.mouse.capture%28v=vs.110%29.aspx [ ^ ],
https:// msdn .microsoft.com / en-us / library / system.windows.input.capturemode%28v = vs.110%29.aspx [ ^ ]。



但是这样的事情只能在相对较短的时间内临时进行。这是一个典型的应用程序:您想要创建某个元素的按钮式行为。比如说,你在这个元素上处理 MouseDown 并改变它的状态,比如它的视图。然后你可能想要处理 MouseUp 来进入元素的主要状态,即使那时鼠标指针离开了元素。然后在 MouseDown 中捕获鼠标,并在处理 MouseUp 后取消捕获。您可以使用代替假设无意义的禁用操作。



-SA

How to disable mouse down outside WPF Window without Platform Invoke?
I want no response when pressing mouse down outside WPF Window.
Is it possible?

> Why?
I have a small window, user presses mouse down to create a circle and then he moves mouse up getting out the window to increase a size of the circle, at the end when he likes the size, he presses mouse down again to save the size, but it is already outside the window, i keep it by Mouse Capture and i don't wanna get another response other than my app's.

You said i can't disable it, i get it as i can't implement what i described above.

But i think i can create a very small not transparent window (because transparent window allows mouse work though itself), make its Style None and keep the window Top Most and Activated moving it under mouse by Mouse Position, it might work, but i never checked and it is not a professional way.

解决方案

The question makes no sense: "mouse down" is something the user does with the physical mouse device, it cannot be disabled. And if you could disable moving the mouse pointer to any area of the screen, it would greatly damage the usability of the whole system. It would be hard to invent more irritating system abuse.

However, if you really want, you can "capture" the mouse by some UI element, to dispatch all software mouse events to this element. Please see:
https://msdn.microsoft.com/en-us/library/system.windows.uielement.capturemouse%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.windows.input.mouse.capture%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.windows.input.capturemode%28v=vs.110%29.aspx[^].

But such things should only be done on temporary basis, for relatively short time. Here is one typical application: you want to create button-like behavior of some element. Say, you fist handle MouseDown on this element and change its state, and, say, it's view. Then you may want to handle MouseUp to get to the main state of the element, even if by that time the mouse pointer moved away from the element. Then you capture mouse in your MouseDown and un-capture after you handle MouseUp. You can use this idea instead of that hypothetical pointless "disable" action.

—SA


这篇关于如何在WPF窗口外禁用鼠标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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