0
我想移动线图像上的帮助。事实上,我正在使用一个循环。当我画一条新线时,应删除上一行。但我不知道如何删除上一行。我试图使用invalidate和处置方法,但它没有奏效。我的代码是:移动线图像上的for循环
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);
}
由于桑迪普。我正在使用窗体和一个picturebox。图像显示在picturebox1中。我想要使用循环,水平和垂直移动图像上的线。在当前代码行中不会被删除。现在清楚了吗? –
您需要重新绘制整个图像(初始),因为您将其投影为位图。更重要的是,你可以画线(像素)顶部 –
但我不想重新绘制图像。必须有其他解决方案。我在想的是我在处置或失效等方面出错。 –