鼠标移动比重绘wpf更快

时间:2016-07-12 14:49:21

标签: c# wpf shape mousemove onmousemove

我定义了从类Shape继承的形状并实现了几何'属性。

以下是一个例子:

public class Landmark : Shape
{
    public override bool IsInBounds(Point currentLocation)
    {

        return (((currentLocation.X >= Location.X - 3) && (currentLocation.X <= Location.X + 3)) && ((currentLocation.Y >= Location.Y - 3) && (currentLocation.Y <= Location.Y + 3)));
    }

    protected override Geometry DefiningGeometry
    {
        get
        {
            var landMark = new EllipseGeometry {Center = Location};

            Stroke = Brushes.Red;
            return landMark;
        }
    }

    protected override void OnIsMouseDirectlyOverChanged(DependencyPropertyChangedEventArgs e)
    {
        StrokeThickness = IsMouseDirectlyOver ? 12 : 6;
        Mouse.OverrideCursor = IsMouseDirectlyOver ? Mouse.OverrideCursor = Cursors.ScrollAll : Mouse.OverrideCursor = Cursors.Arrow;
    }
    protected override void OnMouseMove(MouseEventArgs e)
    {
        if (e.LeftButton == MouseButtonState.Pressed)
        {
            Location = e.GetPosition(this);
            InvalidateVisual();
        }
    }
}

当我点击Shape并移动鼠标时,我希望在新位置重新绘制Shape - 它确实有效。

然而,如果我移动鼠标&#34;也是#34;很快,然后我就离开&#34;离开&#34; OnMouseMove事件,shape卡在鼠标指针和Shape的位置所在的最后位置&#34;同步&#34;。< / p>

这样的问题可以解决吗?

1 个答案:

答案 0 :(得分:4)

是的,by capturing the Mouse

要使其工作,您必须确定何时捕获以及何时释放。由于您希望使用鼠标左键,因此可以在OnMouseDown中捕获并在OnMouseUp中释放鼠标。

相关问题