示例#1
0
        public void Undo(GraphicsList list)
        {
            list.UnselectAll();

            // Add all objects from cloneList to list.
            foreach (DrawObject o in _cloneList)
            {
                list.Add(o);
            }
        }
示例#2
0
        public void Undo(GraphicsList list)
        {
            list.UnselectAll();

            // Add all objects from cloneList to list.
            foreach (DrawObject o in _cloneList)
            {
                list.Add(o);
            }
        }
        /// <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;
            }
            else
            {
                GraphicsList.UnselectAll();
            }

            Refresh(); // in the case selection was changed

            // Show context menu.
            // Context menu items are filled from owner form Edit menu items.
            _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 point from this window coordinates to owner's coordinates.
            point.X += Left;
            point.Y += Top;

            //m_ContextMenu.Show(owner, point);

            //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.
            _contextMenu.Closed += delegate
            {
                if (_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]);
//                    }
                }
            };
        }