private void UndoButton_Click(object sender, EventArgs e)
 {
     if (LastSelectedImageMetadata == null)
     {
         return;
     }
     ImagePixelGrid.Undo();
 }
        public bool OnHotkey(Keys keyData)
        {
            if (ModifierKeys.HasFlag(Keys.Control))
            {
                var key = keyData & ~Keys.Control;
                switch (key)
                {
                case Keys.N:
                    ClearAllPixelsButton.PerformClick();
                    return(true);

                case Keys.I:
                    InverseButton.PerformClick();
                    return(true);

                case Keys.R:
                    ResizeButton.PerformClick();
                    return(true);

                case Keys.C:
                    CopyButton.PerformClick();
                    return(true);

                case Keys.V:
                    PasteButton.PerformClick();
                    return(true);

                case Keys.A:
                    ImageListBox.BeginUpdate();
                    ImageListBox.SelectedIndices.Clear();
                    ImageListBox.SelectedIndices.AddRange(Enumerable.Range(0, ImageListBox.Items.Count));
                    ImageListBox.EndUpdate();
                    return(true);

                case Keys.Up:
                    ShiftUpButton.PerformClick();
                    return(true);

                case Keys.Down:
                    ShiftDownButton.PerformClick();
                    return(true);

                case Keys.Left:
                    ShiftLeftButton.PerformClick();
                    return(true);

                case Keys.Right:
                    ShiftRightButton.PerformClick();
                    return(true);

                case Keys.Z:
                    ImagePixelGrid.Undo();
                    return(true);
                }
            }
            if (ModifierKeys.HasFlag(Keys.Shift))
            {
                var key = keyData & ~(Keys.Control | Keys.Shift);
                switch (key)
                {
                case Keys.Z:
                    ImagePixelGrid.Redo();
                    return(true);
                }
            }

            return(false);
        }