Example #1
0
        /// <summary>
        /// 创建一个指定方向的箭头.
        /// </summary>
        /// <param name="rect">绘制箭头的矩形区域.</param>
        /// <param name="arrowDirection">箭头的方向.</param>
        /// <returns></returns>
        public static GraphicsPath CreateTrackBarThumbPath(Rectangle rect, ThumbArrowDirection arrowDirection)
        {
            GraphicsPath path        = new GraphicsPath();
            PointF       centerPoint = new PointF(rect.X + rect.Width / 2f, rect.Y + rect.Height / 2f);
            float        offset      = 0;

            switch (arrowDirection)
            {
            case ThumbArrowDirection.Left:
            case ThumbArrowDirection.Right:
                offset = rect.Width / 2f - 4;
                break;

            case ThumbArrowDirection.Up:
            case ThumbArrowDirection.Down:
                offset = rect.Height / 2f - 4;
                break;
            }

            switch (arrowDirection)
            {
            case ThumbArrowDirection.Left:
                path.AddLine(rect.X, centerPoint.Y, rect.X + offset, rect.Y);
                path.AddLine(rect.Right, rect.Y, rect.Right, rect.Bottom);
                path.AddLine(rect.X + offset, rect.Bottom, rect.X, centerPoint.Y);
                break;

            case ThumbArrowDirection.Right:
                path.AddLine(rect.Right, centerPoint.Y, rect.Right - offset, rect.Bottom);
                path.AddLine(rect.X, rect.Bottom, rect.X, rect.Y);
                path.AddLine(rect.Right - offset, rect.Y, rect.Right, centerPoint.Y);
                break;

            case ThumbArrowDirection.Up:
                path.AddLine(centerPoint.X, rect.Y, rect.X, rect.Y + offset);
                path.AddLine(rect.X, rect.Bottom, rect.Right, rect.Bottom);
                path.AddLine(rect.Right, rect.Y + offset, centerPoint.X, rect.Y);
                break;

            case ThumbArrowDirection.Down:
                path.AddLine(centerPoint.X, rect.Bottom, rect.X, rect.Bottom - offset);
                path.AddLine(rect.X, rect.Y, rect.Right, rect.Y);
                path.AddLine(rect.Right, rect.Bottom - offset, centerPoint.X, rect.Bottom);
                break;

            case ThumbArrowDirection.LeftRight:
                break;

            case ThumbArrowDirection.UpDown:
                break;

            case ThumbArrowDirection.None:
                path.AddRectangle(rect);
                break;
            }
            path.CloseFigure();
            return(path);
        }
        public static GraphicsPath CreateTrackBarThumbPath(
            Rectangle rect, ThumbArrowDirection arrowDirection)
        {
            GraphicsPath path = new GraphicsPath();
            PointF centerPoint = new PointF(
                rect.X + rect.Width / 2f, rect.Y + rect.Height / 2f);
            float offset = 0;

            switch (arrowDirection)
            {
                case ThumbArrowDirection.Left:
                case ThumbArrowDirection.Right:
                    offset = rect.Width / 2f - 4;
                    break;
                case ThumbArrowDirection.Up:
                case ThumbArrowDirection.Down:
                    offset = rect.Height / 2f - 4;
                    break;
            }

            switch (arrowDirection)
            {
                case ThumbArrowDirection.Left:
                    path.AddLine(
                        rect.X, centerPoint.Y, rect.X + offset, rect.Y);
                    path.AddLine(
                        rect.Right, rect.Y, rect.Right, rect.Bottom);
                    path.AddLine(
                        rect.X + offset, rect.Bottom, rect.X, centerPoint.Y);
                    break;
                case ThumbArrowDirection.Right:
                    path.AddLine(
                        rect.Right, centerPoint.Y, rect.Right - offset, rect.Bottom);
                    path.AddLine(
                        rect.X, rect.Bottom, rect.X, rect.Y);
                    path.AddLine(
                        rect.Right - offset, rect.Y, rect.Right, centerPoint.Y);
                    break;
                case ThumbArrowDirection.Up:
                    path.AddLine(
                        centerPoint.X, rect.Y, rect.X, rect.Y + offset);
                    path.AddLine(
                        rect.X, rect.Bottom, rect.Right, rect.Bottom);
                    path.AddLine(
                        rect.Right, rect.Y + offset, centerPoint.X, rect.Y);
                    break;
                case ThumbArrowDirection.Down:
                    path.AddLine(
                         centerPoint.X, rect.Bottom, rect.X, rect.Bottom - offset);
                    path.AddLine(
                        rect.X, rect.Y, rect.Right, rect.Y);
                    path.AddLine(
                        rect.Right, rect.Bottom - offset, centerPoint.X, rect.Bottom);
                    break;
                case ThumbArrowDirection.LeftRight:
                    break;
                case ThumbArrowDirection.UpDown:
                    break;
                case ThumbArrowDirection.None:
                    path.AddRectangle(rect);
                    break;
            }

            path.CloseFigure();
            return path;
        }
Example #3
0
        private void DrawDefaultThunm(
            Graphics g, Rectangle thumbRect,
            Color begin, Color end, Color border, float mode,
            Orientation orientation, TickStyle tickStyle)
        {
            ThumbArrowDirection direction = ThumbArrowDirection.None;

            switch (orientation)
            {
            case Orientation.Horizontal:
                switch (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 (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;
            }
            using (GraphicsPath path =
                       GraphicsPathHelper.CreateTrackBarThumbPath(
                           thumbRect, direction))
            {
                using (LinearGradientBrush brush = new LinearGradientBrush(
                           thumbRect, 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);
                }
            }

            thumbRect.Inflate(-1, -1);
            using (GraphicsPath path =
                       GraphicsPathHelper.CreateTrackBarThumbPath(
                           thumbRect, direction))
            {
                using (Pen pen = new Pen(InnerBorderColor))
                {
                    g.DrawPath(pen, path);
                }
            }
        }
Example #4
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);
                    }
                }
            }
        }