我想在面板上画一条线,然后在鼠标移动时移动它。为此,我画了一条线,当鼠标移动时,我将这条线重新绘制到新位置,并通过在其上绘制一条带有背景颜色的线来删除前一条线。如果我不使用高质量平滑模式,它可以正常工作。但是如果使用高质量的平滑模式,它会在面板上留下痕迹。有人知道如何解决这个问题吗?谢谢你。这是代码
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;
}
这是 SmoothingMode 的快照
这是没有 SmoothingMode 的快照