Exemplo n.º 1
0
        protected virtual void OnRenderThumb(PaintThumbEventArgs e)
        {
            Graphics            g         = e.Graphics;
            Rectangle           rect      = e.ClipRectangle;
            ControlState        state     = e.ControlState;
            ThumbArrowDirection direction = ThumbArrowDirection.None;
            Color begin  = ColorTable.ThumbBackNormal;
            Color end    = ColorTable.TrackInnerBorder;
            Color border = ColorTable.ThumbBorderNormal;
            float mode   =
                base.Orientation == Orientation.Horizontal ?
                90f : 0f;

            switch (base.Orientation)
            {
            case Orientation.Horizontal:
                switch (base.TickStyle)
                {
                case TickStyle.None:
                case TickStyle.BottomRight:
                    direction = ThumbArrowDirection.Down;
                    break;

                case TickStyle.TopLeft:
                    direction = ThumbArrowDirection.Up;
                    break;

                case TickStyle.Both:
                    direction = ThumbArrowDirection.None;
                    break;
                }
                break;

            case Orientation.Vertical:
                switch (base.TickStyle)
                {
                case TickStyle.TopLeft:
                    direction = ThumbArrowDirection.Left;
                    break;

                case TickStyle.None:
                case TickStyle.BottomRight:
                    direction = ThumbArrowDirection.Right;
                    break;

                case TickStyle.Both:
                    direction = ThumbArrowDirection.None;
                    break;
                }
                break;
            }

            switch (state)
            {
            case ControlState.Hover:
                begin  = ColorTable.ThumbBackHover;
                border = ColorTable.ThumbBorderHover;
                break;
            }

            using (SmoothingModeGraphics sg = new SmoothingModeGraphics(g))
            {
                using (GraphicsPath path =
                           GraphicsPathHelper.CreateTrackBarThumbPath(
                               rect, direction))
                {
                    using (LinearGradientBrush brush = new LinearGradientBrush(
                               rect, begin, end, mode))
                    {
                        Blend blend = new Blend();
                        blend.Positions = new float[] { 0, .2f, .5f, .8f, 1f };
                        blend.Factors   = new float[] { 1f, .7f, 0, .7f, 1f };
                        brush.Blend     = blend;

                        g.FillPath(brush, path);
                    }
                    using (Pen pen = new Pen(border))
                    {
                        g.DrawPath(pen, path);
                    }
                }

                rect.Inflate(-1, -1);
                using (GraphicsPath path =
                           GraphicsPathHelper.CreateTrackBarThumbPath(
                               rect, direction))
                {
                    using (Pen pen = new Pen(ColorTable.TrackInnerBorder))
                    {
                        g.DrawPath(pen, path);
                    }
                }
            }
        }