WPF_获取鼠标相对位置
1、获取鼠标相对当前所在控件img的相对位置
private void Click_Mousemove(object sender, MouseEventArgse) { System.Windows.Controls.Image image = sender as System.Windows.Controls.Image; System.Windows.Point point = e.GetPosition(image);
XYText.Text = string.Format("X:{0},Y:{1}", point.X, point.Y);
}
2.获取鼠标相对当前应用的相对位置
private void img_MouseMove(object sender, MouseEventArgs e) {
System.Windows.Point pt = e.GetPosition(this); XYText.Text = string.Format("X:{0},Y:{1}", pt.X, pt.Y); }

浙公网安备 33010602011771号