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); } }
public static void FillRect(Rectangle rect, Graphics graf, Color color, int cornerRadius) { if (cornerRadius <= 0) { graf.FillRectangle(new SolidBrush(color), rect); } else { GraphicsPath gfxPath = DrawPath.RoundCorner(rect, cornerRadius); graf.FillPath(new SolidBrush(color), gfxPath); } }
public static void FillRectGradient(Rectangle rect, Graphics graf, Color color1, Color color2, SimpleDirection direction, int cornerRadius) { Point p1; switch (direction) { case SimpleDirection.Vertical: p1 = new Point(rect.X + rect.Width / 2, rect.Y); break; case SimpleDirection.Diagonal2: p1 = new Point(rect.Right - cornerRadius, rect.Y + cornerRadius); break; case SimpleDirection.Diagonal: p1 = new Point(rect.X + cornerRadius, rect.Y + cornerRadius); break; default: p1 = new Point(rect.X - 1, rect.Y + rect.Height / 2); break; } Point p2; switch (direction) { case SimpleDirection.Vertical: p2 = new Point(rect.X + rect.Width / 2, rect.Y + rect.Height); break; case SimpleDirection.Diagonal2: p2 = new Point(rect.X + cornerRadius, rect.Bottom - cornerRadius); break; case SimpleDirection.Diagonal: p2 = new Point(rect.Right - cornerRadius, rect.Bottom - cornerRadius); break; default: p2 = new Point(rect.Right + 1, rect.Y + rect.Height / 2); break; } if (cornerRadius <= 0) { if (p1 != p2) { graf.FillRectangle(new LinearGradientBrush(p1, p2, color1, color2), rect); } else { graf.FillRectangle(new SolidBrush(color1), rect); } } else { GraphicsPath gfxPath = DrawPath.RoundCorner(rect, cornerRadius); gfxPath.CloseAllFigures(); if (p1 != p2) { graf.FillPath(new LinearGradientBrush(p1, p2, color1, color2), gfxPath); } else { graf.FillPath(new SolidBrush(color1), gfxPath); } } }