这个问题可以通过以下的代码示例来解决:
private void MouseMoveHandler(object sender, MouseEventArgs e)
{
Point relativePoint = Mouse.GetPosition(this);
Point point = this.PointToScreen(relativePoint);
yourLabel.SetValue(Canvas.LeftProperty, point.X + 10);
yourLabel.SetValue(Canvas.TopProperty, point.Y + 10);
}
在这个示例中,我们可以看到通过Mouse.GetPosition()
方法和PointToScreen()
方法,我们可以得到鼠标相对于窗口的位置,然后通过SetValue()
方法将标签的位置设置为比鼠标指针稍微往右下方偏移10个像素点的位置,这样就可以解决标签位置落后于鼠标指针的问题了。
上一篇:标签位置和大小
下一篇:标签为“创建重置”的帖子