如何更换触点上的鼠标点击
本文关键字:鼠标 何更换 触点 | 更新日期: 2023-09-27 18:03:28
请告诉我,我如何在鼠标点击上类似地替换命令TouchPoint ?我添加了我必须更改的代码:
private Dictionary<int, UIElement> myEllipses =
new Dictionary<int, UIElement>();
private void cnv_MouseDown(object sender, MouseButtonEventArgs e)
{
Ellipse ellipse = new Ellipse();
ellipse.Width = 30;
ellipse.Height = 30;
ellipse.Stroke = Brushes.White;
ellipse.Fill = Brushes.Gold;
TouchPoint tp = e.GetPosition(cnv);
Canvas.SetTop(ellipse, tp.Bounds.Top);
Canvas.SetLeft(ellipse, tp.Bounds.Left);
myEllipses[e.TouchDevice.Id] = ellipse;
cnv.Children.Add(ellipse);
}
尝试GetPosition()
方法获取鼠标被点击的点。试试这个:
private void cnv_MouseDown(object sender, MouseButtonEventArgs e)
{
Point clickedPt = e.GetPosition(this);
var xPos = clickedPt.X;
var yPos = clickedPt.Y;
}