【发布时间】:2015-04-23 11:24:44
【问题描述】:
它适用于特定控件,但不适用于特定控件。
如何获取鼠标位置和使用鼠标事件,而不依赖于任何控件,直接从屏幕(没有平台调用)?
需要2分:
- 鼠标不在控件内,而是在屏幕上时的鼠标事件。
- 鼠标不在控件内,而是在屏幕上时的鼠标位置。
应该不用Platform Invoke来解决。
接下来的两个不起作用:
System.Windows.Input.Mouse.GetPosition(this)
不会将鼠标位置移出特定控件。
System.Windows.Forms.Cursor.Position.X
System.Windows.Forms.Cursor.Position 不起作用,因为它在 WPF 应用程序中没有类型,但它在 Windows 窗体应用程序中起作用。
IntelliSense 获取 System.Windows.Forms.Cursor.Position,但它没有获取任何类型的 Position,因此我无法获取:
Position.X
Position.Y
和
Point pointToWindow = Mouse.GetPosition(this);
Point pointToScreen = PointToScreen(pointToWindow);
不会将鼠标位置移出特定控件。
【问题讨论】:
标签: c# .net wpf c#-4.0 mouse-position