public override void Undo(GraphicsList list) { list.UnselectAll(); // Add all objects from cloneList to list. foreach (DrawObject o in cloneList) { list.Add(o); } }
public override void Undo(GraphicsList list) { list.UnselectAll(); // Add all objects from cloneList to list. int n = cloneList.Count; for (int i = n - 1; i >= 0; i--) { list.Insert(indexList[i], cloneList[i]); } }
/// <summary> /// Right-click handler /// </summary> /// <param name="e"></param> private void OnContextMenu(MouseEventArgs e) { // Change current selection if necessary var point = new Point(e.X, e.Y); int n = GraphicsList.Count; DrawObject o = null; for (int i = 0; i < n; i++) { if (GraphicsList[i].HitTest(point) == 0) { o = GraphicsList[i]; break; } } if (o != null) { if (!o.Selected) { GraphicsList.UnselectAll(); } // Select clicked object o.Selected = true; _bringToFrontToolStripMenuItem.Enabled = true; _sendToBackToolStripMenuItem.Enabled = true; _cutToolStripMenuItem.Enabled = true; _copyToolStripMenuItem.Enabled = true; _deleteToolStripMenuItem.Enabled = true; } else { _bringToFrontToolStripMenuItem.Enabled = false; _sendToBackToolStripMenuItem.Enabled = false; _cutToolStripMenuItem.Enabled = false; _copyToolStripMenuItem.Enabled = false; _deleteToolStripMenuItem.Enabled = false; GraphicsList.UnselectAll(); } _pasteToolStripMenuItem.Enabled = GraphicsList.AreItemsInMemory(); _contextMenuStrip.Show(MousePosition); Refresh(); }
/// <summary> /// Right-click handler /// </summary> /// <param name="e"></param> private void OnContextMenu(MouseEventArgs e) { // Change current selection if necessary Point point = new Point(Math.Abs(this.AutoScrollPosition.X) + e.X, Math.Abs(this.AutoScrollPosition.Y) + e.Y); int n = GraphicsList.Count; DrawObject o = null; for (int i = 0; i < n; i++) { if (GraphicsList[i].HitTest(point) == 0) { o = GraphicsList[i]; break; } } if (o != null) { if (!o.Selected) { GraphicsList.UnselectAll(); } // Select clicked object o.Selected = true; } else { GraphicsList.UnselectAll(); } Refresh(); // in the case selection was changed // Show context menu. // Context menu items are filled from owner form Edit menu items. m_ContextMenu = new ContextMenuStrip(); int nItems = owner.ContextParent.DropDownItems.Count; // Read Edit items and move them to context menu. // Since every move reduces number of items, read them in reverse order. // To get items in direct order, insert each of them to beginning. for (int i = nItems - 1; i >= 0; i--) { m_ContextMenu.Items.Insert(0, owner.ContextParent.DropDownItems[i]); } // Show context menu for owner form, so that it handles items selection. // Convert pointscroll from this window coordinates to owner's coordinates. point.X += this.Left; point.Y += this.Top; Point org = new Point(e.X, e.Y); m_ContextMenu.Show(owner, org); Owner.SetStateOfControls(); // enable/disable menu items // Context menu is shown, but owner's Edit menu is now empty. // Subscribe to context menu Closed event and restore items there. m_ContextMenu.Closed += delegate(object sender, ToolStripDropDownClosedEventArgs args) { if (m_ContextMenu != null) // precaution { nItems = m_ContextMenu.Items.Count; for (int k = nItems - 1; k >= 0; k--) { owner.ContextParent.DropDownItems.Insert(0, m_ContextMenu.Items[k]); } } }; }
public override void Redo(GraphicsList list) { list.UnselectAll(); list.Add(drawObject); }