public GraphicsPath CreateRoundedRectanglePath(Rectangle rect, RoundDirect direct, int cornerRadius) { GraphicsPath roundedRect = new GraphicsPath(); switch (direct) { case RoundDirect.LeftDown: roundedRect.AddLine(rect.X, rect.Y, rect.X + rect.Width, rect.Y); roundedRect.AddLine(rect.X + rect.Width, rect.Y, rect.X + rect.Width, rect.Bottom); roundedRect.AddLine(rect.X + rect.Width, rect.Bottom, rect.X + cornerRadius * 2, rect.Bottom); roundedRect.AddArc(rect.X, rect.Bottom - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 90, 90); roundedRect.AddLine(rect.X, rect.Bottom - cornerRadius * 2, rect.X, rect.Y); roundedRect.CloseFigure(); break; case RoundDirect.RightDown: roundedRect.AddLine(rect.X, rect.Y, rect.X + rect.Width, rect.Y); roundedRect.AddLine(rect.X + rect.Width, rect.Y, rect.X + rect.Width, rect.Bottom - cornerRadius * 2); roundedRect.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y + rect.Height - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 0, 90); roundedRect.AddLine(rect.X + rect.Width - cornerRadius * 2, rect.Bottom, rect.X, rect.Bottom); roundedRect.AddLine(rect.X, rect.Bottom, rect.X, rect.Y); roundedRect.CloseFigure(); break; case RoundDirect.All: roundedRect.AddArc(rect.X, rect.Y, cornerRadius * 2, cornerRadius * 2, 180, 90); roundedRect.AddLine(rect.X + cornerRadius, rect.Y, rect.Right - cornerRadius * 2, rect.Y); roundedRect.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y, cornerRadius * 2, cornerRadius * 2, 270, 90); roundedRect.AddLine(rect.Right, rect.Y + cornerRadius * 2, rect.Right, rect.Y + rect.Height - cornerRadius * 2); roundedRect.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y + rect.Height - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 0, 90); roundedRect.AddLine(rect.Right - cornerRadius * 2, rect.Bottom, rect.X + cornerRadius * 2, rect.Bottom); roundedRect.AddArc(rect.X, rect.Bottom - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 90, 90); roundedRect.AddLine(rect.X, rect.Bottom - cornerRadius * 2, rect.X, rect.Y + cornerRadius * 2); roundedRect.CloseFigure(); break; default: break; } return(roundedRect); }
public GraphicsPath CreateRoundedRectanglePath(Rectangle rect, RoundDirect direct, int cornerRadius) { GraphicsPath roundedRect = new GraphicsPath(); switch (direct) { case RoundDirect.LeftDown: roundedRect.AddLine(rect.X, rect.Y, rect.X + rect.Width, rect.Y); roundedRect.AddLine(rect.X + rect.Width, rect.Y, rect.X + rect.Width, rect.Bottom); roundedRect.AddLine(rect.X + rect.Width, rect.Bottom, rect.X + cornerRadius * 2, rect.Bottom); roundedRect.AddArc(rect.X, rect.Bottom - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 90, 90); roundedRect.AddLine(rect.X, rect.Bottom - cornerRadius * 2, rect.X, rect.Y); roundedRect.CloseFigure(); break; case RoundDirect.RightDown: roundedRect.AddLine(rect.X, rect.Y, rect.X + rect.Width, rect.Y); roundedRect.AddLine(rect.X + rect.Width, rect.Y, rect.X + rect.Width, rect.Bottom - cornerRadius * 2); roundedRect.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y + rect.Height - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 0, 90); roundedRect.AddLine(rect.X + rect.Width - cornerRadius * 2, rect.Bottom, rect.X, rect.Bottom); roundedRect.AddLine(rect.X, rect.Bottom, rect.X, rect.Y); roundedRect.CloseFigure(); break; case RoundDirect.All: roundedRect.AddArc(rect.X, rect.Y, cornerRadius * 2, cornerRadius * 2, 180, 90); roundedRect.AddLine(rect.X + cornerRadius, rect.Y, rect.Right - cornerRadius * 2, rect.Y); roundedRect.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y, cornerRadius * 2, cornerRadius * 2, 270, 90); roundedRect.AddLine(rect.Right, rect.Y + cornerRadius * 2, rect.Right, rect.Y + rect.Height - cornerRadius * 2); roundedRect.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y + rect.Height - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 0, 90); roundedRect.AddLine(rect.Right - cornerRadius * 2, rect.Bottom, rect.X + cornerRadius * 2, rect.Bottom); roundedRect.AddArc(rect.X, rect.Bottom - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 90, 90); roundedRect.AddLine(rect.X, rect.Bottom - cornerRadius * 2, rect.X, rect.Y + cornerRadius * 2); roundedRect.CloseFigure(); break; default: break; } return roundedRect; }