0

am using GraphicsPath to draw Lines so it's like Pen/Brush tool in Paint

   public void OnMouseDown(object sender, MouseEventArgs e)
    {
        start = e.Location;
        path.AddLine(e.Location, new Point(e.Location.X, e.Location.Y));
    }

    public void OnMouseMove(object sender, MouseEventArgs e)
    {
        end = e.Location;
        path.AddLine(e.Location, new Point(e.Location.X, e.Location.Y));
    }

    public void OnMouseUp(object sender, MouseEventArgs e)
    {
        end = e.Location;
        path.AddLine(e.Location, new Point(e.Location.X, e.Location.Y));
    }

    public void OnPaint(object sender, Graphics g)
    {
        g.DrawPath(pen, path);
    }

how would I Relocate it , I have tried Transform method , but it didn't work..

 public void Relocate(MouseEventArgs e)
    {
        Matrix m = new Matrix();
        m.Translate(start.X + e.X - end.X, start.Y + e.Y - end.Y, MatrixOrder.Append);
        path.Transform(m);

    }

so how would I do it the right way? moving the whole drawn shape?

Abanoub
  • 3,623
  • 16
  • 66
  • 104

1 Answers1

1

Have you tried:

  • Separating logic for creating line and moving line? I think you would need it in your implementation to differentiate which operation you are doing.

  • When moving the line, the path can be transformed via your Relocate() method and the following should be sufficient:

    Matrix matrix = new Matrix();
    matrix.Translate( offsetX, offsetY ); //Where offset is the new location
    path.Transform( matrix ); //Transform the path
    

Then do not forget to redraw the path via Invalidate()

Joel Legaspi Enriquez
  • 1,236
  • 1
  • 10
  • 14
  • am separating the logic of-course , and I have tried that `matrix.Translate( offsetX, offsetY ); ` where the new offsets are the mouse location , but that is not working correctly! – Abanoub Aug 04 '15 at 03:20
  • _the new offsets are the mouse location_ of course they should be the distance to the last position..! – TaW Aug 04 '15 at 07:26
  • @TaW and how would I get the distance? – Abanoub Aug 04 '15 at 18:54
  • You need to keep track of the previous position! – TaW Aug 04 '15 at 19:01