private static GraphicsPath CreateBorderPath(Rectangle rect,
Rectangle exclude,
float cut)
{
// If nothing to exclude, then use quicker method
if (exclude.IsEmpty)
return CreateBorderPath(rect, cut);
// Drawing lines requires we draw inside the area we want
rect.Width--;
rect.Height--;
// Create an array of points to draw lines between
List<PointF> pts = new List<PointF>();
float l = rect.X;
float t = rect.Y;
float r = rect.Right;
float b = rect.Bottom;
float x0 = rect.X + cut;
float x3 = rect.Right - cut;
float y0 = rect.Y + cut;
float y3 = rect.Bottom - cut;
float cutBack = (cut == 0f ? 1 : cut);
// Does the exclude intercept the top line
if ((rect.Y >= exclude.Top) && (rect.Y <= exclude.Bottom))
{
float x1 = exclude.X - 1 - cut;
float x2 = exclude.Right + cut;
if (x0 <= x1)
{
pts.Add(new PointF(x0, t));
pts.Add(new PointF(x1, t));
pts.Add(new PointF(x1 + cut, t - cutBack));
}
else
{
x1 = exclude.X - 1;
pts.Add(new PointF(x1, t));
pts.Add(new PointF(x1, t - cutBack));
}
if (x3 > x2)
{
pts.Add(new PointF(x2 - cut, t - cutBack));
pts.Add(new PointF(x2, t));
pts.Add(new PointF(x3, t));
}
else
{
x2 = exclude.Right;
pts.Add(new PointF(x2, t - cutBack));
pts.Add(new PointF(x2, t));
}
}
else
{
pts.Add(new PointF(x0, t));
pts.Add(new PointF(x3, t));
}
pts.Add(new PointF(r, y0));
pts.Add(new PointF(r, y3));
pts.Add(new PointF(x3, b));
pts.Add(new PointF(x0, b));
pts.Add(new PointF(l, y3));
pts.Add(new PointF(l, y0));
// Create path using a simple set of lines that cut the corner
GraphicsPath path = new GraphicsPath();
// Add a line between each set of points
for (int i = 1; i < pts.Count; i++)
path.AddLine(pts[i - 1], pts[i]);
// Add a line to join the last to the first
path.AddLine(pts[pts.Count - 1], pts[0]);
return path;
}