【问题标题】:mouse move is faster than redraw wpf鼠标移动比重绘wpf快
【发布时间】:2016-11-14 21:24:44
【问题描述】:

我正在定义继承自 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 会在新位置重新绘制 - 它确实有效。

但是,如果我“过快”移动鼠标,那么我将“离开”OnMouseMove 事件,并且shape 卡在鼠标指针和Shape 的最后一个位置位置处于“同步”状态。

这样的问题能解决吗?

【问题讨论】:

    标签: c# wpf shape mousemove onmousemove


    【解决方案1】:

    是的,by capturing the Mouse

    为此,您必须确定何时捕获以及何时释放。由于您希望它与鼠标左键一起使用,您可以在OnMouseDown 中捕获并在OnMouseUp 中释放鼠标。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-23
      • 2023-03-22
      • 1970-01-01
      • 2018-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多