private const double ROUNDED_RECT_RAD_PERCENT = .05d;//5 percent

        /// <summary>
        /// Gets the graphics path.
        /// </summary>
        /// <param name="container">The container.</param>
        /// <param name="shape">The shape.</param>
        /// <returns>GraphicsPath.</returns>
        public static GraphicsPath GetGraphicsPath(Rectangle container, ControlShape shape)
        {
            GraphicsPath path = new GraphicsPath();

            Rectangle pathRect = container;

            pathRect.Width  -= 1;
            pathRect.Height -= 1;

            switch (shape)
            {
            case ControlShape.Rect:
                path.AddRectangle(pathRect);
                break;

            case ControlShape.RoundedRect:
                //radius is 10% of smallest side
                int rad = (int)(Math.Min(pathRect.Height, pathRect.Width) * ROUNDED_RECT_RAD_PERCENT);
                CustomExtensions.AddRoundedRectangle(path, pathRect, rad);
                break;

            case ControlShape.Circular:
                path.AddEllipse(pathRect);
                break;
            }

            return(path);
        }
        /// <summary>
        /// Gets the grad brush.
        /// </summary>
        /// <param name="container">The container.</param>
        /// <param name="shape">The shape.</param>
        /// <param name="color">The color.</param>
        /// <returns>Brush.</returns>
        public static Brush GetGradBrush(Rectangle container, ControlShape shape, Color color)
        {
            Brush brush = null;

            switch (shape)
            {
            case ControlShape.Rect:
            case ControlShape.RoundedRect:
                brush = new LinearGradientBrush(container, color, Color.Transparent,
                                                LinearGradientMode.Vertical);
                break;

            case ControlShape.Circular:
                using (GraphicsPath path = new GraphicsPath())
                {
                    path.AddEllipse(container);
                    PathGradientBrush pgb = new PathGradientBrush(path);
                    pgb.CenterColor    = color;
                    pgb.SurroundColors = new Color[] { Color.Transparent };
                    pgb.CenterPoint    = new PointF(container.Left + container.Width * .5f,
                                                    container.Bottom + container.Height);
                    brush = pgb;
                }

                break;
            }

            return(brush);
        }
示例#3
0
        public static Brush GetGradBrush(Rectangle container, ControlShape shape, Color color)
        {
            Brush brush = null;

            switch (shape)
            {
                case ControlShape.Rect:
                case ControlShape.RoundedRect:
                    brush = new LinearGradientBrush(container, color, Color.Transparent,
                        LinearGradientMode.Vertical);
                    break;
                case ControlShape.Circular:
                    using (GraphicsPath path = new GraphicsPath())
                    {
                        path.AddEllipse(container);
                        PathGradientBrush pgb = new PathGradientBrush(path);
                        pgb.CenterColor = color;
                        pgb.SurroundColors = new Color[] { Color.Transparent };
                        pgb.CenterPoint = new PointF(container.Left + container.Width * .5f,
                                                     container.Bottom + container.Height);
                        brush = pgb;
                    }

                    break;
            }

            return brush;
        }
        /// <summary>
        /// Get3s the d shine path.
        /// </summary>
        /// <param name="container">The container.</param>
        /// <param name="shape">The shape.</param>
        /// <returns>GraphicsPath.</returns>
        public static GraphicsPath Get3DShinePath(Rectangle container, ControlShape shape)
        {
            GraphicsPath path = new GraphicsPath();

            Rectangle pathRect = container;

            pathRect.Width  -= 1;
            pathRect.Height -= 1;

            RectangleF halfRect = new RectangleF(pathRect.X, pathRect.Y,
                                                 pathRect.Width, pathRect.Height / 2f);

            if (pathRect.Height > 0 && pathRect.Width > 0)
            {
                switch (shape)
                {
                case ControlShape.Rect:
                    path.AddRectangle(halfRect);
                    break;

                case ControlShape.RoundedRect:
                    //radius is 10% of smallest side
                    int rad = (int)(Math.Min(halfRect.Height, halfRect.Width) * ROUNDED_RECT_RAD_PERCENT);
                    CustomExtensions.AddRoundedRectangle(path, halfRect, rad);
                    break;

                case ControlShape.Circular:
                    path.AddArc(pathRect, 180, 142);
                    PointF[] pts = new PointF[]
                    {
                        path.GetLastPoint(),
                        new PointF(container.Width * .70f, container.Height * .33f),
                        new PointF(container.Width * .25f, container.Height * .5f),
                        path.PathPoints[0]
                    };
                    path.AddCurve(pts);
                    path.CloseFigure();
                    break;
                }
            }

            return(path);
        }
示例#5
0
        private const double ROUNDED_RECT_RAD_PERCENT = .05d; //5 percent

        #endregion Fields

        #region Methods

        public static GraphicsPath Get3DShinePath(Rectangle container, ControlShape shape)
        {
            GraphicsPath path = new GraphicsPath();

            Rectangle pathRect = container;
            pathRect.Width -= 1;
            pathRect.Height -= 1;

            RectangleF halfRect = new RectangleF(pathRect.X, pathRect.Y,
                                                    pathRect.Width, pathRect.Height / 2f);

            if (pathRect.Height > 0 && pathRect.Width > 0)
            {
                switch (shape)
                {
                    case ControlShape.Rect:
                        path.AddRectangle(halfRect);
                        break;
                    case ControlShape.RoundedRect:
                        //radius is 10% of smallest side
                        int rad = (int)(Math.Min(halfRect.Height, halfRect.Width) * ROUNDED_RECT_RAD_PERCENT);
                        path.AddRoundedRectangle(halfRect, rad);
                        break;
                    case ControlShape.Circular:
                        path.AddArc(pathRect, 180, 142);
                        PointF[] pts = new PointF[]
                    {
                        path.GetLastPoint(),
                        new PointF(container.Width * .70f, container.Height * .33f),
                        new PointF(container.Width * .25f, container.Height * .5f),
                        path.PathPoints[0]
                    };
                        path.AddCurve(pts);
                        path.CloseFigure();
                        break;
                }
            }

            return path;
        }
示例#6
0
        public static GraphicsPath GetGraphicsPath(Rectangle container, ControlShape shape)
        {
            GraphicsPath path = new GraphicsPath();

            Rectangle pathRect = container;
            pathRect.Width -= 1;
            pathRect.Height -= 1;

            switch (shape)
            {
                case ControlShape.Rect:
                    path.AddRectangle(pathRect);
                    break;
                case ControlShape.RoundedRect:
                    //radius is 10% of smallest side
                    int rad = (int)(Math.Min(pathRect.Height, pathRect.Width) * ROUNDED_RECT_RAD_PERCENT);
                    path.AddRoundedRectangle(pathRect, rad);
                    break;
                case ControlShape.Circular:
                    path.AddEllipse(pathRect);
                    break;
            }

            return path;
        }