Ejemplo n.º 1
0
        /// <summary>
        /// Creates new image display form supporting mask creation.
        /// </summary>
        /// <param name="title">Window title.</param>
        public DrawingPenForm(string title = "")
            :base(title)
        {
            PictureBox.ContextMenu = new ContextMenu
            {
                Items =
                {
                    new ButtonMenuItem { Text="Increase pen size", Command = new Command((s, e) => changePenSize(true)), Shortcut = Keys.Control | Keys.Up  },
                    new ButtonMenuItem { Text="Decrease pen size", Command = new Command((s, e) => changePenSize(false)), Shortcut = Keys.Control | Keys.Down },
                    new ButtonMenuItem { Text="Undo", Command = new Command((s, e) => adorner.Undo()), Shortcut = Keys.Control | Keys.Z }
                }
            };

            PictureBox.ContextMenu.Opening += (s, e) => 
            {
                PictureBox.ContextMenu.Items[2].Enabled = adorner.CanUndo;
            };

            PictureBox.KeyDown += (s, e) => 
            {
                foreach (var item in PictureBox.ContextMenu.Items)
                {
                    if (item.Shortcut == (e.Modifiers | e.Key))
                    {
                        if (item.Command.CanExecute(null))
                            item.Command.Execute(null);

                        break;
                    }
                }
            };

            adorner = new DrawingPenAdorner(PictureBox);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates new image display form supporting mask creation.
        /// </summary>
        /// <param name="title">Window title.</param>
        public DrawingPenForm(string title = "")
            : base(title)
        {
            PictureBox.ContextMenu = new ContextMenu
            {
                Items =
                {
                    new ButtonMenuItem {
                        Text = "Increase pen size", Command = new Command((s, e) => changePenSize(true)), Shortcut = Keys.Control | Keys.Up
                    },
                    new ButtonMenuItem {
                        Text = "Decrease pen size", Command = new Command((s, e) => changePenSize(false)), Shortcut = Keys.Control | Keys.Down
                    },
                    new ButtonMenuItem {
                        Text = "Undo", Command = new Command((s, e) => adorner.Undo()), Shortcut = Keys.Control | Keys.Z
                    }
                }
            };

            PictureBox.ContextMenu.Opening += (s, e) =>
            {
                PictureBox.ContextMenu.Items[2].Enabled = adorner.CanUndo;
            };

            PictureBox.KeyDown += (s, e) =>
            {
                foreach (var item in PictureBox.ContextMenu.Items)
                {
                    if (item.Shortcut == (e.Modifiers | e.Key))
                    {
                        if (item.Command.CanExecute(null))
                        {
                            item.Command.Execute(null);
                        }

                        break;
                    }
                }
            };

            adorner = new DrawingPenAdorner(PictureBox);
        }