2016-07-12 2 views
3

클래스 Shape에서 상속 한 모양을 정의하고 'Geometry'속성을 구현합니다. 나는 Shape을 클릭하고 내 마우스를 이동하면마우스 이동이 다시 그리기 wpf보다 빠릅니다.

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가 새 위치에 다시 그려야 할 것으로 예상 - 그것은 작업을 수행합니다

다음은 예입니다. 나는 "너무"마우스를 이동하면

그러나, 빨리, 나는이 OnMouseMove 이벤트를 "떠나"야, 그리고 shape 마우스 포인터와 Shape의 위치에 있던 마지막 위치에 걸리면 "동기화 ".

그런 문제를 해결할 수 있습니까?

답변

4

예, by capturing the Mouse.

캡쳐 할시기와 출시시기를 설정해야합니다. 마우스 왼쪽 버튼으로 작업하기를 원하면 OnMouseDown에서 캡처하고 OnMouseUp에서 마우스를 놓을 수 있습니다.

+0

고마워요! 그것은 완벽하게 작동했습니다. – Idanis