2013-07-10 33 views
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); 
       } 

回答

1

它不管你是用帆布或其他一些 技术工作并不清楚。不管怎么说,这里是通用的答案

  • 如果您正在使用位图(Canvas)的工作,你不能修改
    线的位置一样,因为一切都是像素修改对象的位置。
  • 相反,可以有绘制 行上之前被重画的初始图像(输入)。

    只是想知道,你到底想达到什么目的?

+0

由于桑迪普。我正在使用窗体和一个picturebox。图像显示在picturebox1中。我想要使​​用循环,水平和垂直移动图像上的线。在当前代码行中不会被删除。现在清楚了吗? –

+0

您需要重新绘制整个图像(初始),因为您将其投影为位图。更重要的是,你可以画线(像素)顶部 –

+0

但我不想重新绘制图像。必须有其他解决方案。我在想的是我在处置或失效等方面出错。 –