/// <summary>
        /// Returns true to specify the event has been handled and should not be processed any further.
        /// </summary>
        public bool OnKeyDown(KeyEventArgs e)
        {
            if (IsBuildingObject && e.KeyCode == Keys.Escape)
            {
                StopBuildingDynamicObject();
                return(true);
            }

            if (_currentObjectBuilt != null)
            {     // Building an object - send the key to it.
                if (_currentObjectBuilt.AddBuildingKey(e))
                { // Handled by object.
                    Add(_currentObjectBuilt);
                    DynamicObjectBuiltEvent(this, _currentObjectBuilt);
                    _currentObjectBuilt = null;

                    return(true);
                }
            }

            if (e.KeyCode == Keys.Delete && _selectedDynamicCustomObjects.Count > 0)
            {// Delete.
                foreach (DynamicCustomObject dynamicObject in _selectedDynamicCustomObjects)
                {
                    _dynamicCustomObjects.Remove(dynamicObject);
                }

                _selectedDynamicCustomObjects.Clear();
                _pane.Invalidate();
                return(false);
            }

            return(false);
        }
        public bool BuildDynamicObject(DynamicCustomObject dynamicObject)
        {
            if (_currentObjectBuilt != null)
            {
                return(false);
            }

            if (dynamicObject.Initialize(this) == false)
            {
                return(false);
            }

            _currentObjectBuilt = dynamicObject;
            return(true);
        }
        /// <summary>
        /// Returns true to specify the event has been handled and should not be processed any further.
        /// </summary>
        public bool OnKeyPress(KeyPressEventArgs e)
        {
            if (_currentObjectBuilt != null)
            {     // Building an object - send the key to it.
                if (_currentObjectBuilt.AddBuildingKey(e))
                { // Handled by object.
                    Add(_currentObjectBuilt);
                    DynamicObjectBuiltEvent(this, _currentObjectBuilt);
                    _currentObjectBuilt = null;

                    return(true);
                }
            }

            return(false);
        }
 public void StopBuildingDynamicObject()
 {
     _currentObjectBuilt = null;
     DynamicObjectBuiltEvent(this, null);
     _pane.Invalidate();
 }
        /// <summary>
        /// Returns true to specify the event has been handled and should not be processed any further.
        /// </summary>
        public bool OnMouseDown(MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                PointF drawingSpaceLocation = _pane.GraphicsWrapper.ActualSpaceToDrawingSpace(e.Location, true);

                if (_currentObjectBuilt != null)
                {// Building new object.
                    if (_currentObjectBuilt.AddBuildingPoint(drawingSpaceLocation))
                    {
                        Add(_currentObjectBuilt);
                        DynamicObjectBuiltEvent(this, _currentObjectBuilt);
                        _currentObjectBuilt = null;
                    }
                    return true;
                }
                else
                {// Selection.

                    bool result = false;

                    // First check if we must start dragging.
                    foreach (DynamicCustomObject dynamicObject in _selectedDynamicCustomObjects)
                    {
                        if (dynamicObject.TrySelect(_pane.GraphicsWrapper.DrawingSpaceTransform, drawingSpaceLocation, _defaultAbsoluteSelectionMargin, false))
                        {// One of the selected objects was clicked on so start dragging.
                            _dragLastDrawingSpaceMouseLocation = drawingSpaceLocation;
                            result = true;
                            break;
                        }
                    }

                    //if (_dragLastDrawingSpaceMouseLocation.HasValue == false)
                    //{// Only if dragging is not running try to perform typical selection.

                    //    foreach (DynamicCustomObject dynamicObject in _dynamicCustomObjects)
                    //    {
                    //        if (dynamicObject.TrySelect(_pane.DrawingSpaceTransform, drawingSpaceLocation, _defaultAbsoluteSelectionMargin, !_pane.IsControlKeyDown))
                    //        {
                    //            if (result == true)
                    //            {// Only one NEW selection per turn so deny this selection,
                    //                // but keep cycling to perform needed deselections.
                    //                dynamicObject.Selected = false;
                    //            }

                    //            result = true;
                    //        }
                    //    }
                    //}

                    if (result)
                    {
                        _pane.Invalidate();
                    }

                    UpdateSelectedObjects();
                    return result;
                }
            }

            return false;
        }
        /// <summary>
        /// Returns true to specify the event has been handled and should not be processed any further.
        /// </summary>
        public bool OnKeyPress(KeyPressEventArgs e)
        {
            if (_currentObjectBuilt != null)
            {// Building an object - send the key to it.
                if (_currentObjectBuilt.AddBuildingKey(e))
                {// Handled by object.

                    Add(_currentObjectBuilt);
                    DynamicObjectBuiltEvent(this, _currentObjectBuilt);
                    _currentObjectBuilt = null;

                    return true;
                }
            }

            return false;
        }
        /// <summary>
        /// Returns true to specify the event has been handled and should not be processed any further.
        /// </summary>
        public bool OnKeyDown(KeyEventArgs e)
        {
            if (IsBuildingObject && e.KeyCode == Keys.Escape)
            {
                StopBuildingDynamicObject();
                return true;
            }

            if (_currentObjectBuilt != null)
            {// Building an object - send the key to it.
                if (_currentObjectBuilt.AddBuildingKey(e))
                {// Handled by object.

                    Add(_currentObjectBuilt);
                    DynamicObjectBuiltEvent(this, _currentObjectBuilt);
                    _currentObjectBuilt = null;

                    return true;
                }
            }

            if (e.KeyCode == Keys.Delete && _selectedDynamicCustomObjects.Count > 0)
            {// Delete.
                foreach (DynamicCustomObject dynamicObject in _selectedDynamicCustomObjects)
                {
                    _dynamicCustomObjects.Remove(dynamicObject);
                }

                _selectedDynamicCustomObjects.Clear();
                _pane.Invalidate();
                return false;
            }

            return false;
        }
 public void HandleDynamicObjectUpdated(DynamicCustomObject dynamicObject)
 {
     _pane.Invalidate();
 }
        public bool BuildDynamicObject(DynamicCustomObject dynamicObject)
        {
            if (_currentObjectBuilt != null)
            {
                return false;
            }

            if (dynamicObject.Initialize(this) == false)
            {
                return false;
            }

            _currentObjectBuilt = dynamicObject;
            return true;
        }
 public void StopBuildingDynamicObject()
 {
     _currentObjectBuilt = null;
     DynamicObjectBuiltEvent(this, null);
     _pane.Invalidate();
 }
        /// <summary>
        /// Returns true to specify the event has been handled and should not be processed any further.
        /// </summary>
        public bool OnMouseDown(MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                PointF drawingSpaceLocation = _pane.GraphicsWrapper.ActualSpaceToDrawingSpace(e.Location, true);

                if (_currentObjectBuilt != null)
                {// Building new object.
                    if (_currentObjectBuilt.AddBuildingPoint(drawingSpaceLocation))
                    {
                        Add(_currentObjectBuilt);
                        DynamicObjectBuiltEvent(this, _currentObjectBuilt);
                        _currentObjectBuilt = null;
                    }
                    return(true);
                }
                else
                {// Selection.
                    bool result = false;

                    // First check if we must start dragging.
                    foreach (DynamicCustomObject dynamicObject in _selectedDynamicCustomObjects)
                    {
                        if (dynamicObject.TrySelect(_pane.GraphicsWrapper.DrawingSpaceTransform, drawingSpaceLocation, _defaultAbsoluteSelectionMargin, false))
                        {// One of the selected objects was clicked on so start dragging.
                            _dragLastDrawingSpaceMouseLocation = drawingSpaceLocation;
                            result = true;
                            break;
                        }
                    }

                    //if (_dragLastDrawingSpaceMouseLocation.HasValue == false)
                    //{// Only if dragging is not running try to perform typical selection.

                    //    foreach (DynamicCustomObject dynamicObject in _dynamicCustomObjects)
                    //    {
                    //        if (dynamicObject.TrySelect(_pane.DrawingSpaceTransform, drawingSpaceLocation, _defaultAbsoluteSelectionMargin, !_pane.IsControlKeyDown))
                    //        {
                    //            if (result == true)
                    //            {// Only one NEW selection per turn so deny this selection,
                    //                // but keep cycling to perform needed deselections.
                    //                dynamicObject.Selected = false;
                    //            }

                    //            result = true;
                    //        }
                    //    }
                    //}

                    if (result)
                    {
                        _pane.Invalidate();
                    }

                    UpdateSelectedObjects();
                    return(result);
                }
            }

            return(false);
        }
 public void HandleDynamicObjectUpdated(DynamicCustomObject dynamicObject)
 {
     _pane.Invalidate();
 }