2010-12-30 7 views
0
public void read_file(string fname) 
    { 
     filepath = fname; 

     TextReader input = File.OpenText(filepath); 
     line = input.ReadLine(); 
     int[] ID = new int[6]; 
     int[] x = new int[6]; 
     int[] y = new int[6]; 
     int xx, yy; 
     int i = 0; 
     image = AForge.Imaging.Image.FromFile(filename); 
     smal1 = AForge.Imaging.Image.FromFile(smallimg1); 
     smal2 = AForge.Imaging.Image.FromFile(smallimg2); 
     smal3 = AForge.Imaging.Image.FromFile(smallimg3); 
     smal4 = AForge.Imaging.Image.FromFile(smallimg4); 
     smal5 = AForge.Imaging.Image.FromFile(smallimg5); 
     smal6 = AForge.Imaging.Image.FromFile(smallimg6); 


     // int index = 0; 
     while (line != null && line != " ") 
     { 


      if (line == "change") 
      { 
       while (line != "end") 
       { 

        line = input.ReadLine(); 
        line = line.Trim(); 
        if (line != "end") 
        { 
         string[] parts = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); 
         xx = int.Parse(parts[0]); 
         yy = int.Parse(parts[1]); 
         image.SetPixel(xx, yy, Color.Blue); 
        } 

       } 
       line = input.ReadLine(); 
      } 
      else 
      { 
       string[] parts2 = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); 
       ID[i] = int.Parse(parts2[0]); 
       x[i] = int.Parse(parts2[1]); 
       y[i] = int.Parse(parts2[2]); 
       line = input.ReadLine(); 
       if(ID[i]==1) 
       { 
        pictureBox2.Size = smal1.Size; 
        pictureBox2.Image = smal1; 
       } 
       else if (ID[i] == 2) 
       { 
        pictureBox3.Size = smal2.Size; 
        pictureBox3.Image = smal2; 
       } 
       else if (ID[i] == 3) 
       { 
        pictureBox4.Size = smal3.Size; 
        pictureBox4.Image = smal3; 
       } 
       else if (ID[i] == 4) 
       { 
        pictureBox5.Size = smal4.Size; 
        pictureBox5.Image = smal4; 
       } 
       else if (ID[i] == 5) 
       { 
        pictureBox6.Size = smal5.Size; 
        pictureBox6.Image = smal5; 
       } 
       else if (ID[i] == 6) 
       { 
        pictureBox7.Size = smal6.Size; 
        pictureBox7.Image = smal6; 
       } 
        i++; 
      } 
     } 
     // pictureBox2.BackColor = Color.SteelBlue; 
     // pictureBox2.Image = smal; 
     // pictureBox2.Size = smal.Size; 
     pictureBox1.Image = image; 
     pictureBox1.Size = image.Size; 
     //pictureBox2.Hide(); 
    } 

    public Form1() 
    { 
     InitializeComponent(); 
    } 


    private void Form1_Load(object sender, EventArgs e) 
    { 

    } 

    private void Start_Click(object sender, EventArgs e) 
    { 

     capture_flag = true; 
     start_reading(); 

    } 

    private void Stop_Click(object sender, EventArgs e) 
    { 
     capture_flag = false; 
    } 

    private void start_reading() 
    { 

     string filen = "F:/4th year/1st Term/sensor network/proj/reconstructscene/stream.txt"; 
     read_file(filen); 
     filen = "F:/4th year/1st Term/sensor network/proj/reconstructscene/stream1.txt"; 
     read_file(filen); 
     filen = "F:/4th year/1st Term/sensor network/proj/reconstructscene/stream2.txt"; 
     read_file(filen); 

    } 

    private void close_Click(object sender, EventArgs e) 
    { 
     this.Dispose(); 
    } 

위 코드에서 read_file 함수를 여러 번 호출하려고하는데 작동하지 않습니다. 양식이 끝까지 기다렸다가 한 번 그립니다. 원래 프로젝트에서어떻게 런타임에 그림 상자를 그립니 까?

노트 나는 poject의 다른 부분에서 파일 이름을 할게요 그리고 난 같은 이유로

답변

1

이유 작동하지

while (capture_flag) 
     { 

     filen = file; 
     read_file(filen); 
     } 

같은 함수를 호출 할 수 메서드가 실행 중일 때 변경 내용이 표시되지 않습니다. 즉, 주 스레드가 메서드를 실행 중일 때 메시지를 수신하지 않는 것입니다. 업데이트는 메시지 대기열에있는 메시지의 형태로 발생하므로 주 스레드가 메시지를 처리 ​​할 수 ​​없을 때 업데이트가 없습니다.

당신은 방법의 중간에있는 동안 컨트롤의 다시 그리기를 강제로 Refresh 방법을 사용할 수 있습니다 :

pictureBox2.Size = smal1.Size; 
pictureBox2.Image = smal1; 
pictureBox2.Refresh(); 
+0

네는'호출 Refresh'가 잘 작동합니다 아주 많이 ..이 일하고 –

+0

, 감사 && 행복 새해 – Emykindman

+0

하지만 새로운 문제가 있습니다. 드로잉을하는 동안 어떤 버튼을 사용할 수 없지만 프로그램을 중단해야하는 이유는 무엇입니까? – Emykindman