Answer 3
I use the following method which appears to create equal corners when I ScaleTransform the graphics object.
publicstatic GraphicsPath RoundedRectangle(Rectangle bounds, float radius, Corners corners)
{
//Make sure the Path fits inside the rectangle
bounds.Width--;
bounds.Height--;
//Scale the radius if it's too large to fit.if (radius > (bounds.Width))
radius = bounds.Width;
if (radius > (bounds.Height))
radius = bounds.Height;
System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
if (radius <= 0)
path.AddRectangle(bounds);
else
{
if ((corners & Corners.TopLeft) == Corners.TopLeft)
path.AddArc(bounds.Left, bounds.Top, radius, radius, 180, 90);
else
path.AddLine(bounds.Left, bounds.Top, bounds.Left, bounds.Top);
if ((corners & Corners.TopRight) == Corners.TopRight)
path.AddArc(bounds.Right - radius, bounds.Top, radius, radius, 270, 90);
else
path.AddLine(bounds.Right, bounds.Top, bounds.Right, bounds.Top);
if ((corners & Corners.BottomRight) == Corners.BottomRight)
path.AddArc(bounds.Right - radius, bounds.Bottom - radius, radius, radius, 0, 90);
else
path.AddLine(bounds.Right, bounds.Bottom, bounds.Right, bounds.Bottom);
if ((corners & Corners.BottomLeft) == Corners.BottomLeft)
path.AddArc(bounds.Left, bounds.Bottom - radius, radius, radius, 90, 90);
else
path.AddLine(bounds.Left, bounds.Bottom, bounds.Left, bounds.Bottom);
}
path.CloseFigure();
return path;
}
[Flags]
publicenum Corners
{
None = 0,
TopLeft = 1,
TopRight = 2,
BottomLeft = 4,
BottomRight = 8,
All = TopLeft | TopRight | BottomLeft | BottomRight
}