此方法只是鼠标相对于当前窗口的坐标数值,而不是鼠标在电脑屏幕的坐标值。
?
?
注意给控件命名
<TextBlock Name="Textblock2"
FontSize="20"
Width=" 120"
Height=" 50"
FontStretch="Expanded"
VerticalAlignment="Center"
HorizontalAlignment="Center">
</TextBlock>
?
private void Window_MouseMove(object sender, MouseEventArgs e)
{
Point pp = e.GetPosition(this);
Textblock2.Text = string.Format("坐标{0},{1}", pp.X, pp.Y);
}
?
?
?
VS编程,WPF中,获取鼠标相对于当前程序窗口的坐标的一种方法
原文:https://www.cnblogs.com/lonelyxmas/p/10728807.html