Moving a high quality line on a panel c#
Posted
by
user1787601
on Stack Overflow
See other posts from Stack Overflow
or by user1787601
Published on 2012-11-12T03:50:51Z
Indexed on
2012/11/12
5:00 UTC
Read the original article
Hit count: 176
I want to draw a line on a panel and then move it as the mouse moves. To do so, I draw the line and when the mouse moves I redraw the line to the new location and remove the previous line by drawing a line with the background color on it. It works fine if I do not use the high quality smoothing mode. But if use high quality smoothing mode, it leave traces on the panel. Does anybody know how to fix this? Thank you. Here is the code
int x_previous = 0;
int y_previous = 0;
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
Pen pen1 = new System.Drawing.Pen(Color.Black, 3);
Pen pen2 = new System.Drawing.Pen(panel1.BackColor, 3);
Graphics g = panel1.CreateGraphics();
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.DrawLine(pen2, new Point(0, 0), new Point(x_previous, y_previous));
g.DrawLine(pen1, new Point(0, 0), new Point(e.Location.X, e.Location.Y));
x_previous = e.Location.X;
y_previous = e.Location.Y;
}
Here is the snapshot with SmoothingMode
Here is the snapshot without SmoothingMode
© Stack Overflow or respective owner