public static GraphicsPath RoundCorner(Rectangle rect, int radius, RectSides sides)
        {
            GraphicsPath gfxPath = new GraphicsPath();

            if (sides.left)
            {
                gfxPath.AddLine(rect.X, rect.Bottom - radius, rect.X, rect.Y + radius);
                gfxPath.AddLine(rect.X, rect.Y + radius, rect.X + radius, rect.Y);
            }
            if (sides.top)
            {
                gfxPath.AddLine(rect.X + radius, rect.Y, rect.Right - radius, rect.Y);
                gfxPath.AddLine(rect.Right - radius, rect.Y, rect.Right, rect.Y + radius);
            }
            if (sides.right)
            {
                gfxPath.AddLine(rect.Right, rect.Y + radius, rect.Right, rect.Bottom - radius);
                gfxPath.AddLine(rect.Right, rect.Bottom - radius, rect.Right - radius, rect.Bottom);
            }
            if (sides.bottom)
            {
                gfxPath.AddLine(rect.Right - radius, rect.Bottom, rect.X + radius, rect.Bottom);
                gfxPath.AddLine(rect.X + radius, rect.Bottom, rect.X, rect.Bottom - radius);
                gfxPath.AddLine(rect.X, rect.Bottom - radius, rect.X, rect.Bottom - radius - 1);
            }
            return(gfxPath);
        }
        public static GraphicsPath RectSides(Rectangle rect, RectSides sides)
        {
            GraphicsPath gfxPath = new GraphicsPath();

            if (sides.left)
            {
                gfxPath.AddLine(rect.X, rect.Y + rect.Height, rect.X, rect.Y);
            }
            if (sides.top)
            {
                gfxPath.AddLine(rect.X, rect.Y, rect.X + rect.Width, rect.Y);
            }
            if (sides.right)
            {
                gfxPath.AddLine(rect.X + rect.Width, rect.Y, rect.X + rect.Width, rect.Y + rect.Height);
            }
            if (sides.bottom)
            {
                gfxPath.AddLine(rect.X + rect.Width, rect.Y + rect.Height, rect.X, rect.Y + rect.Height);
            }
            return(gfxPath);
        }
 public static void DrawRectangle(Rectangle rect, Graphics graf, Color color, int width, RectSides sides)
 {
     DrawRectangle(rect, graf, color, width, 0, sides);
 }
        public static void DrawRectangle(Rectangle rect, Graphics graf, Color color, int width, int cornerRadius, RectSides sides)
        {
            if (width <= 0)
            {
                return;
            }
            int h        = width / 2;
            int dz       = (2 * h == width) ? 0 : 1;
            int h2       = 2 * h + dz;
            var drawRect = new Rectangle(rect.Left + h, rect.Top + h, rect.Width - h2, rect.Height - h2);

            if (cornerRadius <= 0 && sides.Full)
            {
                graf.DrawRectangle(new Pen(color, width), drawRect);
            }
            else
            {
                GraphicsPath gfxPath;
                if (cornerRadius <= 0)
                {
                    gfxPath = DrawPath.RectSides(drawRect, sides);
                }
                else
                {
                    gfxPath = DrawPath.RoundCorner(drawRect, cornerRadius, sides);
                }
                graf.DrawPath(new Pen(color, width), gfxPath);
            }
        }