/// <summary> /// Opens the upload form /// </summary> /// <param name="sender">Event sender</param> /// <param name="e">Event arguments</param> private void UploadToolStripMenuItem_Click(object sender, EventArgs e) { using (FrmUpload fUpload = new FrmUpload(S)) { if (fUpload.ShowDialog() == DialogResult.OK) { ShowImages((ImageFilter)lvImages.Tag, CurrentPage = 1, (bool)tbFilter.Tag ? null : tbFilter.Text); } } }
/// <summary> /// End of Drag and Drop handler. /// Processes file drops /// </summary> /// <param name="sender">Event sender</param> /// <param name="e">Event arguments</param> private void FrmMain_DragDrop(object sender, DragEventArgs e) { if (e.Data.GetFormats().Contains("FileDrop")) { //This is always a string array, even for single file drops string[] Data = (string[])e.Data.GetData("FileDrop"); //BeginInvoke seems stupid because the event is already fired in the correct thread, //but this prevents the Drop event from getting "stuck" BeginInvoke((MethodInvoker) delegate { bool Render = false; foreach (string FileName in Data) { if (File.Exists(FileName)) { try { Image.FromFile(FileName).Dispose(); } catch { MessageBox.Show($"{Path.GetFileName(FileName)} is not a valid image", "Invalid Image", MessageBoxButtons.OK, MessageBoxIcon.Error); continue; } using (FrmUpload f = new FrmUpload(S, FileName)) { if (f.ShowDialog() != DialogResult.OK) { break; } else { Render = true; } } } } if (Render) { ShowImages((ImageFilter)lvImages.Tag, CurrentPage = 1, (bool)tbFilter.Tag ? null : tbFilter.Text); } }); } else { BeginInvoke((MethodInvoker) delegate { MessageBox.Show("Only files are allowed to be dropped", "Invalid Drag&Drop Operation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); }); } }