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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
private Path selPath = null;
private PathGeometry pg1 = null;
private bool dragmod = false; //not yet used
Point p0, p1;
double dx, dy;
private void itemcanvas_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
Canvas cn;
cn = (sender as Canvas);
selPath = new Path();
selPath = EnumVisual(cn) as Path;
pg1 = selPath.Data as PathGeometry;
p0 = e.GetPosition(cn);
}
private void itemcanvas_PreviewMouseMove(object sender, MouseEventArgs e)
{
if (selPath!=null)
{
Canvas cn;
cn = (sender as Canvas);
p1 = e.GetPosition(cn);
dx = p1.X - p0.X;
dy = p1.Y - p0.Y;
TransletPath(pg1, dx, dy);
p0 = p1;
//this.txb1.Text = "dx: "+dx.ToString()+"dy: "+dy.ToString();
}
}
private void itemcanvas_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
if (selPath == null) return;
//liberer la capture souris par un click droit
//selPath.ReleaseMouseCapture();
selPath = null;
}
public void TransletPath(PathGeometry mypt,double dltx , double dlty)
{
TranslateTransform Tr = new TranslateTransform(dltx, dlty);
pg1.Transform = Tr;
//mypt.Transform= new TranslateTransform(dltx, dlty);
//Canvas ss = mypt.Parent as Canvas;
//double xx = Canvas.GetLeft(mypt);
//double yy = Canvas.GetTop(mypt);
//Canvas.SetLeft(mypt, Canvas.GetLeft(mypt) + dltx)
//Canvas.SetTop(mypt, Canvas.GetTop(mypt) + dlty);
}
static public Visual EnumVisual(Visual myVisual)
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(myVisual); i++)
{
// Retrieve child visual at specified index value.
Visual childVisual = (Visual)VisualTreeHelper.GetChild(myVisual, i);
if (childVisual.GetType()== typeof(Path))
{
return childVisual;
}
// Enumerate children of the child visual object.
EnumVisual(childVisual);
}
return myVisual;
} |
Partager