I am having the user click a point on screen, and until they choose the second point, the line will follow the cursor. Once the second point is drawn it will stay. I am using a double buffer like so:
public void EnableDoubleBuffering()
{
this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
}
I will call that function in the Form_Load();
I am doing the draw like so:
void draw(int x1, int y1, int x2, int y2)
{
Graphics formGraphics = pictureEdit1.CreateGraphics();
Pen myPen = new Pen(Color.Red, 3);
formGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
formGraphics.DrawLine(myPen, x1, y1, x2, y2);
myPen.Dispose();
formGraphics.Dispose();
}
I repetatively call that function from the MouseMove event;
void pictureEdit1_MouseMove(object sender, MouseEventArgs e)
{
if (click == 1 && !rightClicked)
{
pictureEdit1.Invalidate();
trail.X = e.X;
trail.Y = e.Y;
draw(p1.X, p1.Y, trail.X, trail.Y);
}
else if (click != 1)
{
draw(p1.X, p1.Y, trail.X, trail.Y);
}
}
There is a very slight flicker that occurs and it is driving me insane! Please help, thanks.