我定义了从类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>
这样的问题可以解决吗?
答案 0 :(得分:4)
要使其工作,您必须确定何时捕获以及何时释放。由于您希望使用鼠标左键,因此可以在OnMouseDown
中捕获并在OnMouseUp
中释放鼠标。