/// <summary> /// Event handler method for the DragDrop action, performs validation and imports image properties into program. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MainForm_DragDrop(object sender, DragEventArgs e) { // Create a string array that contains complete file paths to the imported files string[] itemArray = (string[])e.Data.GetData(DataFormats.FileDrop); // Validate the imported items with the AreAllImageFiles method if (Validation.AreAllImageFiles(itemArray)) { // If the array is successfully validated, try to clear any existing items in the // ListView and ImageObjectList and then populate them with new values try { Logic.ClearItemsFromObjectList(ImageObjectList); View.ClearItemsFromListView(lvItemList); Logic.PopulateImageObjectList(itemArray, ImageObjectList); View.PopulateListView(ImageObjectList, lvItemList); } catch (ArgumentException) { // Display an 'unexpected error' MessageBox when an ArgumentException is thrown PresetMessageBox.UnexpectedError(""); } } else { // Display a 'File Type Error' MessageBox when the array is not validated successfully PresetMessageBox.FileTypeError(); } }
/// <summary> /// Event handler method for the 'Process Images' button click action, performs validation and opens ConfirmForm /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BtnImportImages_Click(object sender, EventArgs e) { // Initialize an OpenFileDialog object to let user select files using (OpenFileDialog importImagesDialog = new OpenFileDialog()) { // Set the MultiSelect property of OpenFileDialog to true to allow selecting multiple images in one import importImagesDialog.Multiselect = true; // Show dialog and check if the result is 'OK' if (importImagesDialog.ShowDialog() == DialogResult.OK) { // Create a string array that contains complete file paths to the imported files selected in OpenFileDialog string[] itemsFilePaths = importImagesDialog.FileNames; // Validate the imported items with the AreAllImageFiles method if (Validation.AreAllImageFiles(itemsFilePaths)) { try { // If the array is successfully validated, try to clear any existing items in the // ListView and ImageObjectList and then populate them with new values Logic.ClearItemsFromObjectList(ImageObjectList); View.ClearItemsFromListView(lvItemList); Logic.PopulateImageObjectList(itemsFilePaths, ImageObjectList); View.PopulateListView(ImageObjectList, lvItemList); } catch (ArgumentException) { // Display an 'unexpected error' MessageBox when an ArgumentException is thrown PresetMessageBox.UnexpectedError(""); } } else { // Display a 'File Type Error' MessageBox when the array is not validated successfully PresetMessageBox.FileTypeError(); } } } }