如何获取flowlayout面板中的所有数据并复制到文件夹

How to get all the data in flowlayout panel and copy to folder

当我在 flowayoutpanel 中浏览多个图像路径时,我设法做到了,然后单击按钮保存,所有图像路径将保存到一个文件夹,我的问题是我可以浏览图像路径并在 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);

    }
}

显然你必须将文件名存储在某个地方,或者像你一样在文本框中(尽管我建议改为 tb.Text=file!),或者你使用单独的 List<string>(我建议后者!使用表格来存储东西基本上不是一个好主意)。

要获取文件,只需迭代 foreach(Control c in flowLayoutPanel1.Items),然后将 SubControls 转到您的文本框或使用单独的列表。

您可以使用 File.Copy(src, dest) 进行的复制。