So I realise doing:
panel1.CreateGraphics()
is heavily looked down upon, but I'm making a paint app and I can't see any other way of doing it, simply because if I call panel1.Invalidate();
it obviously does not save the lines the user has drawn.
So here's my code:
private void pnlPaintPanel_MouseDown(object sender, MouseEventArgs e)
{
shouldPaint = true;
prePoint = new Point(e.X, e.Y);
}
private void pnlPaintPanel_MouseUp(object sender, MouseEventArgs e)
{
shouldPaint = false;
}
private void pnlPaintPanel_MouseMove(object sender, MouseEventArgs e)
{
curPoint = new Point(e.X, e.Y);
if (shouldPaint)
{
pnlPaintPanel.Invalidate();
}
prePoint = new Point(e.X, e.Y);
}
private void pnlPaintPanel_Paint(object sender, PaintEventArgs e)
{
using (Pen p = new Pen(chosenColor, penSize))
{
p.StartCap = LineCap.Round;
p.EndCap = LineCap.Round;
e.Graphics.DrawLine(p, prePoint, curPoint);
}
}
This obviously doesn't work because it just clears any paint the user puts down immediately. I'm sure there's a clever way of doing it; can anyone help?
>! Sounds complicated? Not when you think about it: You want several (list1) curves (list2)..