我想在图像上移动一条线。事实上我正在使用一个循环。当我画一条新线时,应该删除前一行。但我不知道如何删除上一行。我尝试使用 invalidate 和 dispose 方法,但它不起作用。我的代码是:
int xinc = 0, yinc = 0;
for (int loop = 0; loop <= 363; loop++)
{
Thread.Sleep(200);
MethodInvoker actionimage1 = delegate
{
Graphics g = pictureBox1.CreateGraphics();
if (loop <= 117)
{
Pen p = new Pen(Color.Red, 4.0f);
g.DrawLine(p, 0, xinc, 363, xinc);
g.Clear(this.BackColor);
this.Dispose();
this.Invalidate();
xinc++;
}
if (loop <= 363)
{
Pen p = new Pen(Color.Red, 4.0f);
g.DrawLine(p, yinc, 0, yinc, 117);
g.Clear(this.BackColor);
this.Dispose(); // I need here to remove the line,
such that when loop starts again the
sholud be on next coordinate.
this.Invalidate();
yinc++;
}
};
pictureBox1.BeginInvoke(actionimage1);
}