Exemplo n.º 1
0
        private void menuAdd_Click(object sender, EventArgs e)
        {
            var dlg = new OpenFileDialog
            {
                Title       = "Add Photos",
                Multiselect = true,
                Filter      = "Image Files (JPEG, GIF, BMP, etc.)|" +
                              "*.jpg;*.jpeg;*.gif;*.bmp;*.tif;*.tiff;*.png|" +
                              "JPEG files (*.jpg;*.jpeg)|*.jpg;*.jpeg |" +
                              "GIF files  (*.gif)|*.gif |" +
                              "BMP files  (*.bmp)|*.bmp |" +
                              "TIFF files  (*.tif;*.tiff)|*.tif;*.tiff |" +
                              "PNG files  (*.png)|*.png |" +
                              "All files  (*.*)|*.*",
                InitialDirectory = @"D:\CurrentWork\Tmp"
            };

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                var files = dlg.FileNames;
                updateStatus(string.Format("Loading {0} Files", files.Length));
                foreach (var file in files)
                {
                    var photo = new Photograph(file);
                    if (_album.IndexOf(photo) < 0)
                    {
                        _album.Add(photo);
                        _bAlbumChanged = true;
                    }
                }

                dlg.Dispose();
                Invalidate();
            }
        }
Exemplo n.º 2
0
        private void menuAdd_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Title            = "Add photos to the album";
            dlg.Multiselect      = true;
            dlg.Filter           = ".JPG(.jpg)|*.jpg|.PNG(.png)|*.png|All files(*.*)|*.*";
            dlg.CheckFileExists  = true;
            dlg.InitialDirectory = Environment.CurrentDirectory;

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    string[] fileNames = dlg.FileNames;

                    sbpnlFileName.Text = $"Loading {fileNames.Length} files";

                    int index = 0;
                    foreach (var fileName in fileNames)
                    {
                        Photograph p = new Photograph(fileName);
                        index = _album.IndexOf(p);

                        if (index < 0)
                        {
                            _album.Add(p);
                            _albumChanged = true;
                        }
                    }
                }
                catch (Exception exception)
                {
                    sbpnlFileName.Text = "Unable to load " + dlg.FileName;

                    MessageBox.Show("Unable to load file: " + exception.Message);
                }
                finally
                {
                    dlg.Dispose();
                }

                Invalidate();
            }
        }