private static void AddSmoothPath(GraphicsPath borderPath,
VisualOrientation orientation,
Rectangle rect,
bool forBorder)
{
// The tension of the lines depends on the width/height
int minLength = Math.Min(rect.Width, rect.Height);
int calcLength = Math.Min(minLength, 50);
float tension = Math.Max(0.5f - (0.5f / 50 * calcLength), 0.05f);
int indentW = Math.Min(5, rect.Width / 10);
int indentH = Math.Min(5, rect.Height / 10);
switch (orientation)
{
case VisualOrientation.Top:
// If there is not enough room for the rounded style then use the rounded
if (rect.Width < 14)
AddRoundedPath(borderPath, orientation, rect, forBorder);
else
{
if (!forBorder)
borderPath.AddLine(rect.Right, rect.Bottom, rect.Left, rect.Bottom);
// Find way points along the width
int x2T = rect.Width / 2;
int x6T = rect.Width / 6;
borderPath.AddCurve(new Point[]{new Point(rect.Left, rect.Bottom),
new Point(rect.Left + indentW, rect.Top + 5),
new Point(rect.Left + x6T, rect.Top + 2),
new Point(rect.Left + x2T, rect.Top),
new Point(rect.Right - x6T, rect.Top + 2),
new Point(rect.Right - indentW, rect.Top + 5),
new Point(rect.Right, rect.Bottom)}, tension);
}
break;
case VisualOrientation.Bottom:
// If there is not enough room for the rounded style then use the rounded
if (rect.Width < 14)
AddRoundedPath(borderPath, orientation, rect, forBorder);
else
{
if (!forBorder)
borderPath.AddLine(rect.Right, rect.Top, rect.Left, rect.Top);
// Find way points along the width
int x2B = rect.Width / 2;
int x6B = rect.Width / 6;
borderPath.AddCurve(new Point[]{new Point(rect.Left, rect.Top),
new Point(rect.Left + indentW, rect.Bottom - 5),
new Point(rect.Left + x6B, rect.Bottom - 2),
new Point(rect.Left + x2B, rect.Bottom),
new Point(rect.Right - x6B, rect.Bottom - 2),
new Point(rect.Right - indentW, rect.Bottom - 5),
new Point(rect.Right, rect.Top)}, tension);
}
break;
case VisualOrientation.Left:
// If there is not enough room for the rounded style then use the rounded
if (rect.Height < 14)
AddRoundedPath(borderPath, orientation, rect, forBorder);
else
{
if (!forBorder)
borderPath.AddLine(rect.Right, rect.Top, rect.Right, rect.Bottom);
// Find way points along the width
int y2L = rect.Height / 2;
int y6L = rect.Height / 6;
borderPath.AddCurve(new Point[]{new Point(rect.Right, rect.Bottom),
new Point(rect.Left + 5, rect.Bottom - indentH),
new Point(rect.Left + 2, rect.Bottom - y6L),
new Point(rect.Left, rect.Bottom - y2L),
new Point(rect.Left + 2, rect.Top + y6L),
new Point(rect.Left + 5, rect.Top + indentH),
new Point(rect.Right, rect.Top)}, tension);
}
break;
case VisualOrientation.Right:
// If there is not enough room for the rounded style then use the rounded
if (rect.Height < 14)
AddRoundedPath(borderPath, orientation, rect, forBorder);
else
{
if (!forBorder)
borderPath.AddLine(rect.Left, rect.Top, rect.Left, rect.Bottom);
// Find way points along the width
int y2R = rect.Height / 2;
int y6R = rect.Height / 6;
borderPath.AddCurve(new Point[]{new Point(rect.Left, rect.Bottom),
new Point(rect.Right - 5, rect.Bottom - indentH),
new Point(rect.Right - 2, rect.Bottom - y6R),
new Point(rect.Right, rect.Bottom - y2R),
new Point(rect.Right - 2, rect.Top + y6R),
new Point(rect.Right - 5, rect.Top + indentH),
new Point(rect.Left, rect.Top)}, tension);
}
break;
}
}