示例#1
0
        /// <summary>
        /// Handles when a mouse button has been pressed down on this <see cref="Control"/>.
        /// This is called immediately before <see cref="Control.OnMouseDown"/>.
        /// Override this method instead of using an event hook on <see cref="Control.MouseDown"/> when possible.
        /// </summary>
        /// <param name="e">The event args.</param>
        protected virtual void OnMouseDown(MouseButtonEventArgs e)
        {
            // Give the control the focus
            if ((CanFocus || CanDrag) && GetChild(e.Location(), true) == null)
            {
                GUIManager.FocusedControl = this;

                // Drag the control if possible
                if (CanDrag)
                {
                    _dragOffset = e.Location() - Position;
                    if (!_isDragging)
                    {
                        _isDragging = true;
                        InvokeBeginDrag();
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// Handles when this <see cref="Control"/> was clicked.
        /// This is called immediately before <see cref="Control.OnClick"/>.
        /// Override this method instead of using an event hook on <see cref="Control.OnClick"/> when possible.
        /// </summary>
        /// <param name="e">The event args.</param>
        protected override void OnClick(MouseButtonEventArgs e)
        {
            base.OnClick(e);

            if (!IsEnabled || !IsVisible)
                return;

            int lineIndex;
            int lineCharIndex;
            GetCharacterAtPoint(e.Location(), out lineIndex, out lineCharIndex);

            _lines.MoveTo(lineIndex);
            CursorLinePosition = lineCharIndex;
        }