gpt4 book ai didi

c# - 如何在鼠标单击时替换 TouchPoint

转载 作者:太空宇宙 更新时间:2023-11-03 12:40:50 27 4
gpt4 key购买 nike

请告诉我,如何在鼠标单击时类似地替换命令 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com