返回首页

C#2008中

我的FlowLayout面板中显示多个图像文件,现在我想在数据库中保存这些文件。我怎样才能选择这些文件的名字吗?

public frmMultiSelectFile()

        {

            InitializeComponent();

        InitializeOpenFileDialog();

        }

 

private void InitializeOpenFileDialog()

{

    // Set the file dialog to filter for graphics files.

    this.openFileDialog1.Filter =

        "Images (*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|" +

        "All files (*.*)|*.*";

    // Allow the user to select multiple images.

    this.openFileDialog1.Multiselect = true;

    this.openFileDialog1.Title = "My Image Browser";

   

}

 

private void butSelect_Click(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

                    {

                        PictureBox pb = new PictureBox();

                        Image loadedImage = Image.FromFile(file);

                        pb.Height = 100;

                        pb.Width = 115;

                        pb.Image = loadedImage;

                        pb.SizeMode=

                            PictureBoxSizeMode.StretchImage;

 

                        flowLayoutPanel1.Controls.Add(pb);

   

                    }

                   

                    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);

                    }

                }

 

            }

        }

回答

评论会员: 时间:2