如何在wpf中获得鼠标相对当前控件的位置
1个回答
展开全部
<DockPanel MouseMove="DockPanel_MouseMove" Width="300" Height="200" VerticalAlignment="Center" HorizontalAlignment="Center"碰派竖 Background="White">
<Border BorderBrush="Silver" BorderThickness="3">
<Grid>
<TextBlock Name="txt"羡差 Text="test"></TextBlock>
</Grid>
</Border>
</DockPanel>
private void DockPanel_MouseMove(object sender, MouseEventArgs e)
{
Point p = e.GetPosition((IInputElement)sender);
txt.Text = "x:" + p.X + " y:" + p.Y;
}
使用DockPanel的示例如上代码所示,注册MouseMove事件笑大,在后台进行处理就Ok了
<Border BorderBrush="Silver" BorderThickness="3">
<Grid>
<TextBlock Name="txt"羡差 Text="test"></TextBlock>
</Grid>
</Border>
</DockPanel>
private void DockPanel_MouseMove(object sender, MouseEventArgs e)
{
Point p = e.GetPosition((IInputElement)sender);
txt.Text = "x:" + p.X + " y:" + p.Y;
}
使用DockPanel的示例如上代码所示,注册MouseMove事件笑大,在后台进行处理就Ok了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询