13-小练习-鼠标移动显示鼠标的位置

鼠标移动

添加一个显示鼠标位置的程序

private void Rectangle_MouseMove(object sender, MouseEventArgs e)
{
    var point = e.GetPosition(this);
    this.textBlock.Text = "X:" + point.X + " Y:" + point.Y;
}Code language: JavaScript (javascript)
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*"></RowDefinition>
        <RowDefinition Height="30"></RowDefinition>
    </Grid.RowDefinitions>
    <Rectangle Grid.Row="0" Fill="Black" MouseMove="Rectangle_MouseMove"></Rectangle>
    <TextBlock Name="textBlock" Height="30" Grid.Row="1"></TextBlock>
</Grid>Code language: HTML, XML (xml)

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注