private void btnAdd_Click(object sender, EventArgs e) { string[] files = AlbumController.OpenPhotographs(); if (files == null) { return; } int index = -1; foreach (string s in files) { Photograph photo = new Photograph(s); // Add the file (if not already present) index = Manager.Album.IndexOf(photo); if (index < 0) { Manager.Album.Add(photo); } else { photo.Dispose(); // photo already there } } if (index >= 0) { Manager.Index = index; } DisplayAlbum(); }
private void mnuEditAdd_Click(object sender, EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.Title = "Add Photos"; dlg.Multiselect = true; dlg.Filter = "Image Files (JPEG, GIF, BMP, ect.)|*.jpg;*.jpeg;*.gif;*.bmp;*.tiff;*.png|" + "JPGE files (*.jpg;*.fpeg)|*.jpg;*.jpeg|" + "GIF files (*.gif)|*.gif|" + "BMP files (*.bmp)|*.bmp|" + "TIFF files (*.tif;*.tiff)|*.tif;*.tiff|" + "PNG files (*.png)|*.png|" + "All files (*.*)|*.*"; dlg.InitialDirectory = Environment.CurrentDirectory; if (dlg.ShowDialog() == DialogResult.OK) { string[] files = dlg.FileNames; int index = 0; foreach (string s in files) { Photograph photo = new Photograph(s); index = Manager.Album.IndexOf(photo); if (index < 0) { Manager.Album.Add(photo); } else { photo.Dispose(); } } Manager.Index = Manager.Album.Count - 1; } dlg.Dispose(); DisplayAlbum(); }
public void PhotographDispose_BitmapDispose() { var photo = new Photograph(fileName); photo.Dispose(); Assert.True(photo.IsDisposed()); }