예제 #1
0
        public static Region DrawRoundedRectangle(this Graphics g, Color color, Rectangle rec, int radius, ExtendedButtonSettings.RoundedCorners corners, Pen pen, Brush br = null, bool outline = false, bool maskRegion = false)
        {
            using (var b = new SolidBrush(color)) {
                int       x        = rec.X;
                int       y        = rec.Y;
                int       width    = rec.Width - 1;
                int       height   = rec.Height - 1;
                int       diameter = radius * 2;
                Rectangle r        = rec;

                Region retRegion;

                using (GraphicsPath gp = new GraphicsPath()) {
                    if ((corners & ExtendedButtonSettings.RoundedCorners.TopLeft) == ExtendedButtonSettings.RoundedCorners.TopLeft)
                    {
                        gp.AddArc(r.X, r.Y, (radius * 2) - 1, (radius * 2) - 1, 180, 90); // TL
                    }
                    else
                    {
                        gp.AddLine(x, 12, x, y); // TL
                    }
                    if ((corners & ExtendedButtonSettings.RoundedCorners.TopRight) == ExtendedButtonSettings.RoundedCorners.TopRight)
                    {
                        gp.AddArc((r.X + width) - (radius * 2), r.Y, (radius * 2), (radius * 2), 270, 90); // TR
                    }
                    else
                    {
                        gp.AddLine(r.Width - 1, y, rec.Width - 1, y + 12); // TR
                    }
                    if ((corners & ExtendedButtonSettings.RoundedCorners.BottomRight) == ExtendedButtonSettings.RoundedCorners.BottomRight)
                    {
                        gp.AddArc((r.X + width) - (radius * 2), (r.Y + height) - (radius * 2), (radius * 2), (radius * 2), 0, 90); // BR
                    }
                    else
                    {
                        gp.AddLine(rec.Width - 1, 12, rec.Width - 1, rec.Height - 1); // BR
                    }
                    if ((corners & ExtendedButtonSettings.RoundedCorners.BottomLeft) == ExtendedButtonSettings.RoundedCorners.BottomLeft)
                    {
                        gp.AddArc(r.X, (r.Y + height) - (radius * 2), (radius * 2), (radius * 2), 90, 90); // BL
                    }
                    else
                    {
                        gp.AddLine(x + diameter, rec.Height - 1, x, rec.Height - 1); // BL
                    }
                    gp.CloseAllFigures();

                    if (outline)
                    {
                        g.DrawPath(pen, gp);
                    }
                    else
                    {
                        if (br != null)
                        {
                            g.FillPath(br, gp);
                        }
                        else
                        {
                            g.FillPath(b, gp);
                        }
                    }
                    retRegion = new Region(gp);
                }

                return(retRegion);
            }
        }
예제 #2
0
        public static Region CreateRegion(this Graphics g, Rectangle rec, int radius, ExtendedButtonSettings.RoundedCorners corners)
        {
            int       x        = rec.X;
            int       y        = rec.Y;
            int       width    = rec.Width - 1;
            int       height   = rec.Height - 1;
            int       diameter = radius * 2;
            Rectangle r        = rec;
            Region    controlRegion;

            using (GraphicsPath gp = new GraphicsPath()) {
                if ((corners & ExtendedButtonSettings.RoundedCorners.TopLeft) == ExtendedButtonSettings.RoundedCorners.TopLeft)
                {
                    gp.AddArc(r.X, r.Y, (radius * 2) - 1, (radius * 2) - 1, 180, 90); // TL
                }
                else
                {
                    gp.AddLine(x, 12, x, y); // TL
                }
                if ((corners & ExtendedButtonSettings.RoundedCorners.TopRight) == ExtendedButtonSettings.RoundedCorners.TopRight)
                {
                    gp.AddArc((r.X + width) - (radius * 2), r.Y, (radius * 2), (radius * 2), 270, 90); // TR
                }
                else
                {
                    gp.AddLine(r.Width - 1, y, rec.Width - 1, y + 12); // TR
                }
                if ((corners & ExtendedButtonSettings.RoundedCorners.BottomRight) == ExtendedButtonSettings.RoundedCorners.BottomRight)
                {
                    gp.AddArc((r.X + width) - (radius * 2), (r.Y + height) - (radius * 2), (radius * 2), (radius * 2), 0, 90); // BR
                }
                else
                {
                    gp.AddLine(rec.Width - 1, 12, rec.Width - 1, rec.Height - 1); // BR
                }
                if ((corners & ExtendedButtonSettings.RoundedCorners.BottomLeft) == ExtendedButtonSettings.RoundedCorners.BottomLeft)
                {
                    gp.AddArc(r.X, (r.Y + height) - (radius * 2), (radius * 2), (radius * 2), 90, 90); // BL
                }
                else
                {
                    gp.AddLine(x + diameter, rec.Height - 1, x, rec.Height - 1); // BL
                }
                gp.CloseAllFigures();

                controlRegion = new Region(gp);
            }
            return(controlRegion);
        }