0

我需要移动一个物体,我可以上下左右移动它,但是在对角线上失败了,这就是我移动的方式。

if (e.Key == Key.Up && Canvas.GetTop(Good) > 31)
            {
                double top = Canvas.GetTop(Good);
                Canvas.SetTop(Good, top - 7);
            }
            if (e.Key == Key.Down && Canvas.GetTop(Good) < CanvasA.ActualHeight - 7 - Good.Height)
            {
                double down = Canvas.GetTop(Good);
                Canvas.SetTop(Good, down + 7);

            }
            if (e.Key == Key.Left && Canvas.GetLeft(Good) > -2)
            {
                double left = Canvas.GetLeft(Good);
                Canvas.SetLeft(Good, left - 7);

            }
            if (e.Key == Key.Right && Canvas.GetLeft(Good) < CanvasA.ActualWidth - Good.Width)
            {
                double right = Canvas.GetLeft(Good);
                Canvas.SetLeft(Good, right + 7);
            }
        }

    }

一切正常,但无法单击两个按钮以对角线移动字符,之所以少于31,是因为我在WPF中做了Menu。

4

0 回答 0