how to make a rounded rectangle in c# code example
Example: rounded rectangle in C#
using System.Drawing;
using System.Drawing.Drawing2D;
internal static class Converter
{
public static Pen ToPen(this Brush b)
{
return new Pen(b);
}
}
internal sealed class RoundRect1
{
public static GraphicsPath CreateRoundRect(int x, int y, int w, int h, int r)
{
int r2 = r * 2;
GraphicsPath p = new GraphicsPath();
p.AddArc(x, y, r2, r2, 180, 90);
p.AddArc(x + w - r2, y, r2, r2, 270, 90);
p.AddArc(x + w - r2, y + h - r2, r2, r2, 0, 90);
p.AddArc(x, y + h - r2, r2, r2, 90, 90);
p.CloseFigure();
return p;
}
public void FillArea(Rectangle area, int radius, Color fillColor)
{
GraphicsPath gfxPath = RoundRect1.CreateRoundRect(area.X, area.Y, area.Width, area.Height, radius);
Region region = new Region(gfxPath);
SmoothingMode originalAliasing = gfx.SmoothingMode;
gfx.SmoothingMode = SmoothingMode.HighQuality;
gfx.FillPath(fillColor.ToBrush(), gfxPath);
gfx.DrawPath(new Pen(fillColor), gfxPath);
gfx.SetClip(region, CombineMode.Replace);
gfx.SmoothingMode = originalAliasing;
}
}