小编Ziy*_*rov的帖子

如何在WPF中获得鼠标在屏幕上的位置?

它在特定控件中工作,但它不能解决特定控件.

如何直接从屏幕上获取鼠标位置并独立于任何控件使用鼠标事件(没有平台调用)?

2需要点:

  1. 鼠标不在控件内但在屏幕上时的鼠标事件.
  2. 鼠标不在控件内但在屏幕上时的鼠标位置.

它应该在不使用Platform Invoke的情况下解决.

接下来两个不起作用:

System.Windows.Input.Mouse.GetPosition(this)
Run Code Online (Sandbox Code Playgroud)

不会将鼠标定位到特定控件.

System.Windows.Forms.Cursor.Position.X
Run Code Online (Sandbox Code Playgroud)

System.Windows.Forms.Cursor.Position 不起作用,因为它在WPF应用程序中没有类型,但它适用于Windows窗体应用程序.

IntelliSense获取System.Windows.Forms.Cursor.Position,但它没有获得任何类型的Position,因此我无法得到:

Position.X    
Position.Y
Run Code Online (Sandbox Code Playgroud)

Point pointToWindow = Mouse.GetPosition(this);

Point pointToScreen = PointToScreen(pointToWindow);
Run Code Online (Sandbox Code Playgroud)

不会将鼠标定位到特定控件.

.net c# wpf mouse-position c#-4.0

14
推荐指数
2
解决办法
3万
查看次数

标签 统计

.net ×1

c# ×1

c#-4.0 ×1

mouse-position ×1

wpf ×1