1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
private Path selPath = null;//selected path
private PathGeometry pg1 = null;
private TranslateTransform tr = null;
private Point p0, p1;
private double dx, dy;
private int count = 0;
private void itemcanvas_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
dx = dy = 0;
selPath = null;
pg1 = null;
FrameworkElement elem = e.OriginalSource as FrameworkElement;
if (elem == null) return;
if (elem.GetType() != typeof(Path)) return;
selPath = elem as Path;
if (selPath == null) return;
selPath.CaptureMouse();
pg1 = selPath.Data as PathGeometry;
if (pg1 == null ) return;
tr = pg1.Transform as TranslateTransform;
p0 = e.GetPosition(selPath);
}
private void itemcanvas_PreviewMouseMove(object sender, MouseEventArgs e)
{
if (selPath != null)
{
p1 = e.GetPosition(selPath);
dx = p1.X - p0.X;
dy = p1.Y - p0.Y;
tr.X += dx;
tr.Y += dy;
p0 = p1;
}
}
private void itemcanvas_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
if (selPath == null) return;
//liberer la capture souris
selPath.ReleaseMouseCapture();
dx = dy = 0;
selPath = null;
pg1 = null;
} |