示例#1
0
        /// <summary>
        /// Handle mouse down
        /// </summary>
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            m_lastLocation = e.Location;
            SetTransformedLocation(e.Location);
            m_originalLocation = m_transformed_location;
            if (e.Button == MouseButtons.Left)
            {
                IElement clickedElement = FindElementAt(Point.Round(m_transformed_location), true);
                if (clickedElement != null)
                {
                    clickedElement.As <IMouseDownHandler>()?.OnMouseDown(e);
                    if (clickedElement.CanBeSelected && !clickedElement.Selected)
                    {
                        Selection.UnselectAll();
                        Selection.AddElement(clickedElement);
                        BringElementToFront(clickedElement);
                    }

                    m_dragElement = true;
                }
                else
                {
                    m_dragElement = false;
                }

                SelectedElement = clickedElement;
                if (SelectedElement != null)
                {
                    SelectedElement.Selected = true;
                }
            }
        }