void pictureBox_MouseDown(object sender, MouseEventArgs e) { if ((Control.ModifierKeys & Keys.Control) == Keys.Control) { PictureControlDesc desc = findDescription(sender as PictureBox); if (desc != null) { showNextImage(desc, ImageAction.Skip, null); } return; } if ((Control.ModifierKeys & Keys.Alt) == Keys.Alt) { PictureControlDesc desc = findDescription(sender as PictureBox); if (desc != null) { showNextImage(desc, ImageAction.Move, null); } return; } PictureBox pictureBox = (sender as PictureBox); if (e.Button != System.Windows.Forms.MouseButtons.Left) { mLastMenuPictureBox = pictureBox; return; } }
private void skipToolStripMenuItem_Click(object sender, EventArgs e) { PictureControlDesc desc = findDescription(mLastMenuPictureBox); if (desc != null) { showNextImage(desc, ImageAction.Skip, null); } }
private void AddPictureBox() { PictureBox pictureBox = new PictureBox(); pictureBox.SizeMode = PictureBoxSizeMode.CenterImage; pictureBox.BackColor = Color.Black; pictureBox.Visible = false; pictureBox.MouseDown += new MouseEventHandler(pictureBox_MouseDown); pictureBox.ContextMenuStrip = contextMenuStrip1; this.Controls.Add(pictureBox); PictureControlDesc desc = new PictureControlDesc(); desc.mPictureBox = pictureBox; mPictures.Add(desc); }
void showNextImage(PictureControlDesc picture, ImageAction action, StackableImage next) { System.Drawing.Image img = next == null ? null : next.Image; if (picture.mPictureBox.Image != null) { picture.mPictureBox.Image.Dispose(); } if (img == null) { picture.mPictureBox.Image = null; } else { try { //TODO: optimize picture.mPictureBox.Image = (System.Drawing.Image)img.Clone(); } catch (Exception ex) { MessageBox.Show("This is the exception I'm searched for! " + ex.ToString(), "", MessageBoxButtons.OK, MessageBoxIcon.Error); } } if (picture.mImageDescriptor != null) { switch (action) { case ImageAction.Reuse: mImagesLoader.Return(picture.mImageDescriptor.Path); break; case ImageAction.Delete: picture.mImageDescriptor.Dispose(); try { if (string.IsNullOrEmpty(mOptions.MoveDeletedPath)) { System.IO.File.Delete(picture.mImageDescriptor.Path); } else { moveFile(picture.mImageDescriptor.Path, mOptions.MoveDeletedPath); } } catch (IOException ex) { System.IO.File.SetAttributes(picture.mImageDescriptor.Path, FileAttributes.Normal); // do nothing } catch (UnauthorizedAccessException ex) { if (System.IO.File.GetAttributes(picture.mImageDescriptor.Path).HasFlag(System.IO.FileAttributes.ReadOnly)) { System.IO.File.SetAttributes(picture.mImageDescriptor.Path, FileAttributes.Normal); System.IO.File.Delete(picture.mImageDescriptor.Path); } } break; case ImageAction.Move: { picture.mImageDescriptor.Dispose(); string movePath = mOptions.MovePath; moveFile(picture.mImageDescriptor.Path, movePath); } break; case ImageAction.Skip: picture.mImageDescriptor.Dispose(); break; } } picture.mImageDescriptor = next; }