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); }

 

 
 
posted @ 2022-06-08 15:57  驼七  阅读(39)  评论(0)    收藏  举报