public static System.Drawing.Drawing2D.GraphicsPath RoundedRect(Rectangle rect, int cornerradius, int margin, Corner roundedcorners) { return(RoundedRect(CtrlHelper.CheckedRectangleF(rect.Left, rect.Top, rect.Width, rect.Height), cornerradius, margin, roundedcorners)); }
public static System.Drawing.Drawing2D.GraphicsPath RoundedRect(RectangleF rect, int cornerradius, int margin, Corner roundedcorners) { System.Drawing.Drawing2D.GraphicsPath p = new System.Drawing.Drawing2D.GraphicsPath(); float x = rect.X; float y = rect.Y; float w = rect.Width; float h = rect.Height; int m = margin; int r = cornerradius; p.StartFigure(); //top left arc if (System.Convert.ToBoolean(roundedcorners & Corner.TopLeft)) { p.AddArc(CtrlHelper.CheckedRectangleF(x + m, y + m, 2 * r, 2 * r), 180, 90); } else { p.AddLine(new PointF(x + m, y + m + r), new PointF(x + m, y + m)); p.AddLine(new PointF(x + m, y + m), new PointF(x + m + r, y + m)); } //top line p.AddLine(new PointF(x + m + r, y + m), new PointF(x + w - m - r, y + m)); //top right arc if (System.Convert.ToBoolean(roundedcorners & Corner.TopRight)) { p.AddArc(CtrlHelper.CheckedRectangleF(x + w - m - 2 * r, y + m, 2 * r, 2 * r), 270, 90); } else { p.AddLine(new PointF(x + w - m - r, y + m), new PointF(x + w - m, y + m)); p.AddLine(new PointF(x + w - m, y + m), new PointF(x + w - m, y + m + r)); } //right line p.AddLine(new PointF(x + w - m, y + m + r), new PointF(x + w - m, y + h - m - r)); //bottom right arc if (System.Convert.ToBoolean(roundedcorners & Corner.BottomRight)) { p.AddArc(CtrlHelper.CheckedRectangleF(x + w - m - 2 * r, y + h - m - 2 * r, 2 * r, 2 * r), 0, 90); } else { p.AddLine(new PointF(x + w - m, y + h - m - r), new PointF(x + w - m, y + h - m)); p.AddLine(new PointF(x + w - m, y + h - m), new PointF(x + w - m - r, y + h - m)); } //bottom line p.AddLine(new PointF(x + w - m - r, y + h - m), new PointF(x + m + r, y + h - m)); //bottom left arc if (System.Convert.ToBoolean(roundedcorners & Corner.BottomLeft)) { p.AddArc(CtrlHelper.CheckedRectangleF(x + m, y + h - m - 2 * r, 2 * r, 2 * r), 90, 90); } else { p.AddLine(new PointF(x + m + r, y + h - m), new PointF(x + m, y + h - m)); p.AddLine(new PointF(x + m, y + h - m), new PointF(x + m, y + h - m - r)); } //left line p.AddLine(new PointF(x + m, y + h - m - r), new PointF(x + m, y + m + r)); //close figure... p.CloseFigure(); return(p); }