使用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);
}
那我该如何以正确的方式做到这一点?移动整个绘制的形状?
答案 0 :(得分:1)
你试过了吗?
分离创建直线和移动线的逻辑?我认为你需要在实现中区分你正在做的操作。
移动该行时,可以通过path
方法转换Relocate()
,以下内容就足够了:
Matrix matrix = new Matrix();
matrix.Translate( offsetX, offsetY ); //Where offset is the new location
path.Transform( matrix ); //Transform the path
然后不要忘记通过path
Invalidate()