示例#1
0
        /// <summary>
        /// This event handler is called when someone presses the mouse on a surface.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SurfaceMouseDown(object sender, MouseEventArgs e)
        {
            _mouseStart = e.Location;

            // check contextmenu
            if (e.Button == MouseButtons.Right)
            {
                DrawableContainerList selectedList = null;
                if (selectedElements != null && selectedElements.Count > 0)
                {
                    selectedList = selectedElements;
                }
                else
                {
                    // Single element
                    IDrawableContainer rightClickedContainer = _elements.ClickableElementAt(_mouseStart.X, _mouseStart.Y);
                    if (rightClickedContainer != null)
                    {
                        selectedList = new DrawableContainerList(ID);
                        selectedList.Add(rightClickedContainer);
                    }
                }
                if (selectedList != null && selectedList.Count > 0)
                {
                    selectedList.ShowContextMenu(e, this);
                }
                return;
            }

            _mouseDown = true;
            _isSurfaceMoveMadeUndoable = false;

            if (_cropContainer != null && ((_undrawnElement == null) || (_undrawnElement != null && DrawingMode != DrawingModes.Crop)))
            {
                RemoveElement(_cropContainer, false);
                _cropContainer = null;
                _drawingElement = null;
            }

            if (_drawingElement == null && DrawingMode != DrawingModes.None)
            {
                if (_undrawnElement == null)
                {
                    DeselectAllElements();
                    if (_undrawnElement == null)
                    {
                        CreateUndrawnElement();
                    }
                }
                _drawingElement = _undrawnElement;
                // if a new element has been drawn, set location and register it
                if (_drawingElement != null)
                {
                    _drawingElement.Status = _undrawnElement.DefaultEditMode;
                    _drawingElement.PropertyChanged += ElementPropertyChanged;
                    if (!_drawingElement.HandleMouseDown(_mouseStart.X, _mouseStart.Y))
                    {
                        _drawingElement.Left = _mouseStart.X;
                        _drawingElement.Top = _mouseStart.Y;
                    }
                    AddElement(_drawingElement);
                    _drawingElement.Selected = true;
                }
                _undrawnElement = null;
            }
            else
            {
                // check whether an existing element was clicked
                // we save mouse down element separately from selectedElements (checked on mouse up),
                // since it could be moved around before it is actually selected
                _mouseDownElement = _elements.ClickableElementAt(_mouseStart.X, _mouseStart.Y);

                if (_mouseDownElement != null)
                {
                    _mouseDownElement.Status = EditStatus.MOVING;
                }
            }
        }