0

GraphicsPath用来画画Lines,所以它就像Pen/Brush工具一样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);
    }

我怎么会Relocate呢,我试过Transform方法,但它没有工作..

 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);

    }

那么我将如何以正确的方式做到这一点?移动整个绘制的形状?

4

1 回答 1

1

你有没有尝试过:

  • 创建线和移动线的分离逻辑?我认为您在实现中需要它来区分您正在执行的操作。

  • 移动线时,path可以通过您的Relocate()方法进行转换,以下内容就足够了:

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

然后不要忘记重绘pathviaInvalidate()

于 2015-08-04T02:53:04.900 回答