2017-10-19 7 views
0

flowayoutpanel에서 여러 이미지 경로를 탐색하고 버튼 저장을 클릭하면 모든 이미지 경로가 폴더에 저장됩니다. 내 문제는 i입니다. 이미지 경로를 탐색하고 flowlayoutpanel에 표시 할 수 있지만 그곳에서 이미지 경로를 가져 와서 폴더에 복사하는 방법을 알고 있습니다. 어떤 제안이 있습니까? 내가 추천 할 것입니다하지만 당신이 (처럼 텍스트 상자에 하나, 이미지 경로를 찾아 Flowlayoutpanel에서flowlayout 패널의 모든 데이터를 가져와 폴더에 복사하는 방법

private void button1_Click_2(object sender, EventArgs e) 
     { 
      DialogResult dr = this.openFileDialog1.ShowDialog(); 
      if (dr == System.Windows.Forms.DialogResult.OK) 
      { 
       // Read the files 
       foreach (String file in openFileDialog1.FileNames) 
       { 
        // Create a PictureBox. 
        try 
        { 
         Panel panel = new Panel(); 
         PictureBox pb = new PictureBox(); 
         TextBox tb = new TextBox(); 
         Image loadedImage = Image.FromFile(file); 
         pb.Height = 200; 
         pb.Width = 200; 
         pb.Image = loadedImage; 
         pb.SizeMode = PictureBoxSizeMode.StretchImage; 
         tb.Text = openFileDialog1.FileName; 
         //panel.Controls.Add(pb); 
         panel.Controls.Add(tb); 
         panel.Height = 200; 
         panel.Width = 200; 
         flowLayoutPanel1.Controls.Add(panel); 

        } 
        catch (SecurityException ex) 
        { 
         // The user lacks appropriate permissions to read files, discover paths, etc. 
         MessageBox.Show("Security error. Please contact your administrator for details.\n\n" + 
          "Error message: " + ex.Message + "\n\n" + 
          "Details (send to Support):\n\n" + ex.StackTrace 
         ); 
        } 
        catch (Exception ex) 
        { 
         // Could not load the image - probably related to Windows file system permissions. 
         MessageBox.Show("Cannot display the image: " + file.Substring(file.LastIndexOf('\\')) 
          + ". You may not have permission to read the file, or " + 
          "it may be corrupt.\n\nReported error: " + ex.Message); 
        } 


       } 
      } 

private void button2_Click(object sender, EventArgs e) 
{ 

    foreach(TextBox tb in TextBoxes) 
    { 


     File.Copy(tb.Text, dest); 

    } 
} 

답변

0

은 분명히 당신이 어딘가에 파일 이름을 저장해야 표시 방법

은 *입니다 tb.Text=file 대신에!) 또는 별도의 List<string>을 사용하고 있습니다 (후자를 추천합니다! 양식을 사용하여 물건을 보관하는 것은 좋지 않습니다).

파일을 가져 오려면 foreach(Control c in flowLayoutPanel1.Items)을 반복하고 SubControls를 텍스트 상자로 이동하거나 별도의 목록을 사용하십시오.

File.Copy(src, dest)으로 복사 할 수 있습니다.

+0

현재 패널에 자식이 있고 각 패널에는 텍스트 상자와 그림 상자 (자식으로 표시)가있는 flowPanel이 있습니다. 이제는 텍스트 상자가 각 패널의 첫 번째 하위 컨트롤이되어야합니다. – casiosmu

+0

감사합니다. 두 번째 단추의 텍스트 상자 flowlayoutpanel에 텍스트를 정의하는 방법은 무엇입니까? – tang

+0

제발 생각해보십시오 : 당신의'c.Text'는 빈 결과를 줄 것입니다. 물론 패널의 텍스트입니다.하지만 패널의 자식으로부터 텍스트를 원합니다. – casiosmu