2011-04-21 2 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

e.Graphics을 사용하여 그림 상자의 Paint 이벤트에 그래프를 그려야합니다.
강제로 다시 그리려면 pictureBox2.Invalidate()으로 전화하십시오.

CreateGraphics()에 그리지 마십시오. 다음에 컨트롤을 그릴 때 지워집니다.

+0

정말 고마워요! 이것은 정말로 도움이된다! –

+0

반갑습니다. 빈 확인을 클릭하여이 대답을 수락해야합니다. – SLaks