2011-04-21 63 views
0

我正在Windows Mobile智能设备应用程序上绘制一个图片框。该图表运行良好,但之后立即消失。如何使照片保持在Picturebox上?

我用行:

this.Invoke(new EventHandler(picture2_show)); 

和我的画法:

private void picture2_show(object sender, EventArgs e) 
{ 
    using (Graphics objGraphics = this.pictureBox2.CreateGraphics()) 
    { 
     Pen redpen = new Pen(Color.Red, 1); 
     int picBoxWidth = pictureBox2.Size.Width; 
     int picBoxHeight = pictureBox2.Size.Height; 
     int halfWidth = pictureBox2.Size.Width/2; 
     int halfHeight = pictureBox2.Size.Height/2; 

     Graphics objGraphic = this.pictureBox2.CreateGraphics(); 

     objGraphic.DrawLine(redpen, 0, 0, 0, picBoxHeight); 
     objGraphic.DrawLine(redpen, 0, picBoxHeight - 1, picBoxWidth, picBoxHeight - 1); 
     //Rectangle first = new Rectangle(0, halfHeight, picBoxWidth, halfHeight); 

     Pen bpen = new Pen(Color.LawnGreen, 3); 
     for (int i = 0; i < array.Length - 1; i++) 
     { 
      objGraphic.DrawLine(
       bpen, 
       pictureBox2.Size.Width * i/array.Length, 
       pictureBox2.Size.Height - array[i], 
       pictureBox2.Size.Width * (i + 1)/array.Length, 
       pictureBox2.Size.Height - array[i + 1]); 
     } 
    } 
} 

PictureBox的停留,但如何使图不会消失?

帮助非常感谢!

回答

1

您需要在图片框的Paint事件中使用e.Graphics绘制图表。
要强制重绘,请拨打pictureBox2.Invalidate()

不要在CreateGraphics()上画,因为当控件下一次绘制时它将被擦除。

+0

非常感谢!这真的很有帮助! – 2011-04-22 17:09:57

+0

不客气。你应该通过点击空心支票来接受这个答案。 – SLaks 2011-04-22 17:22:50