请说一下,如何在单击鼠标时类似地替换命令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;
}

关于c# - 如何在鼠标单击时替换TouchPoint,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39062931/

10-11 20:00