2013-07-10 44 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

但我不想重新繪製圖像。必須有其他解決方案。我在想的是我在處置或失效等方面出錯。 –