예제 #1
0
        /// <summary>
        /// Mouse down
        /// </summary>
        public void HandleMouseDown(object sender, MouseEventArgs e)
        {
            if (!HasScroll)
            {
                return;
            }
            if (e != null && e.Button != MouseButtons.Left)
            {
                return;
            }

            var mousePosRelativeToThis = _parent.PointToClient(Cursor.Position);

            // mouse in scrollbar
            if (BarRect.Contains(mousePosRelativeToThis))
            {
                var thumbRect = ThumbRect;
                if (IsVertical)
                {
                    thumbRect.X     -= ThumbPadding;
                    thumbRect.Width += ThumbPadding * 2;
                }
                else
                {
                    thumbRect.Y      -= ThumbPadding;
                    thumbRect.Height += ThumbPadding * 2;
                }

                // mouse in thumb
                if (thumbRect.Contains(mousePosRelativeToThis))
                {
                    IsThumbPressed            = true;
                    _mouseMoveInThumbPosition = IsVertical ? mousePosRelativeToThis.Y - thumbRect.Y : mousePosRelativeToThis.X - thumbRect.X;
                }
                else
                {
                    // hover button up
                    if (ScrollButtonUp.Contains(mousePosRelativeToThis))
                    {
                        IsButtonUpPressed = true;
                        Value            -= SmallChange;
                    }
                    else
                    {
                        // hover button down
                        if (ScrollButtonDown.Contains(mousePosRelativeToThis))
                        {
                            IsButtonDownPressed = true;
                            Value += SmallChange;
                        }
                        else
                        {
                            // scroll to click position
                            MoveThumb(IsVertical ? mousePosRelativeToThis.Y : mousePosRelativeToThis.X);
                        }
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Mouse move
        /// </summary>
        public void HandleMouseMove(object sender, MouseEventArgs e)
        {
            if (!HasScroll)
            {
                return;
            }

            // hover bar
            var mousePosRelativeToThis = _parent.PointToClient(Cursor.Position);

            if (BarRect.Contains(mousePosRelativeToThis))
            {
                IsHovered = true;

                // hover thumb
                if (ThumbRect.Contains(mousePosRelativeToThis))
                {
                    IsThumbHovered = true;
                }
                else
                {
                    IsThumbHovered = false;

                    // hover button up
                    if (ScrollButtonUp.Contains(mousePosRelativeToThis))
                    {
                        IsButtonUpHovered = true;
                    }
                    else
                    {
                        IsButtonUpHovered = false;

                        // hover button down
                        if (ScrollButtonDown.Contains(mousePosRelativeToThis))
                        {
                            IsButtonDownHovered = true;
                        }
                        else
                        {
                            IsButtonDownHovered = false;
                        }
                    }
                }
            }
            else
            {
                IsHovered           = false;
                IsThumbHovered      = false;
                IsButtonUpHovered   = false;
                IsButtonDownHovered = false;
            }

            // move thumb
            if (IsThumbPressed)
            {
                MoveThumb(IsVertical ? mousePosRelativeToThis.Y - _mouseMoveInThumbPosition : mousePosRelativeToThis.X - _mouseMoveInThumbPosition);
            }
        }