【发布时间】:2009-01-13 00:58:00
【问题描述】:
无论光标是否在我的应用程序窗口上,我都希望能够访问鼠标的坐标。
当我使用 Mouse.Capture(IInputElement) 或 UIElement.CaptureMouse() 时,两者都无法捕获鼠标并返回 false。
我的问题可能是什么?
我的窗口的cs文件如下:
using System.Windows;
using System.Windows.Input;
namespace ScreenLooker
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
bool bSuccess = Mouse.Capture(this);
bSuccess = this.CaptureMouse();
}
protected override void OnMouseMove(MouseEventArgs e)
{
tbCoordX.Text = e.GetPosition(this).X.ToString();
tbCoordY.Text = e.GetPosition(this).Y.ToString();
//System.Drawing.Point oPoint = System.Windows.Forms.Cursor.Position;
//tbCoordX.Text = oPoint.X.ToString();
//tbCoordY.Text = oPoint.Y.ToString();
base.OnMouseMove(e);
}
}
}
【问题讨论】: