它在特定控件中工作,但它不能解决特定控件.
如何直接从屏幕上获取鼠标位置并独立于任何控件使用鼠标事件(没有平台调用)?
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)
不会将鼠标定位到特定控件.