示例#1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Multiselect = true;

            if (ofd.ShowDialog(this) == DialogResult.OK)
            {
                List <Image> images      = new List <Image>();
                int          countFailed = 0;
                foreach (string fileName in ofd.FileNames)
                {
                    try
                    {
                        Image img = Image.FromFile(fileName);
                        images.Add(img);
                    }
                    catch (Exception)
                    {
                        countFailed++;
                    }
                }
                if (countFailed > 0)
                {
                    MessageBox.Show(String.Format("Failed to add {0} files", countFailed));
                }

                foreach (Image img in images)
                {
                    Commercial commercial = new Commercial();
                    commercial.SetImage(img);
                    this._prodcut.Commercials.Add(commercial);
                }

                this.BindGridView();
            }
        }