如何在鼠标单击时替换 TouchPoint
How to replace TouchPoint on mouse click
请教一下,如何在鼠标单击时类似地替换命令 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;
}
请教一下,如何在鼠标单击时类似地替换命令 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;
}