I’ve been tring to draw a smooth line by mouse clicking. What I noticed is that I can draw smooth line when the form is loaded or when I use button to draw it, but not with the mouse event.
So after a lot of testing, I tried to just draw line when window loads. Then on moouse click create a new paint handeler and call Canvas.Invalidate()
private void panelCanvas_Paint(object sender, PaintEventArgs e)
{
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
e.Graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
Pen pen = new Pen(Color.Black, (float)2.5);
e.Graphics.DrawLine(pen, new Point(0,0), new Point(1000,135));
}
private void panelCanvas_MouseClick(object sender, MouseEventArgs e)
{
Canvas.Paint += new PaintEventHandler(panelCanvas_Paint);
Canvas.Invalidate();
}
After each click my smooth line gets more and more jagged as seen in the pictures.
This behavior does not occure when I redraw canvas using my line button.
I don’t understand why that is? Anybody knows?
Thank you for help.
Line drawn when window loads
Line gets jaggen with clicking
Jaroslav is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.