Semakin sering kita melihat banyak orang yang hendak menggambar kotak dengan sudut yang melengkung atau Rounded Rectangle. Namun ternyata .NET Framework tidak menyediakan fungsi untuk menggambar rounded rectangle ini. Setelah mencoba-coba dan mencari informasi di Google, akhirnya saya menemukan dan kemudian menyempurnakan fungsi untuk menggambar rounded rectangle ini.

public void DrawRoundedRectangle(Graphics canvas, Pen pen, Rectangle rect, int RoundWidth, int RoundHeight)
{
// Make a container for our rounded rectangle figure
System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
// Draw all the rounded corner
gp.AddArc(rect.X, rect.Y, RoundWidth, RoundHeight, 180, 90);
gp.AddArc(rect.X + rect.Width – RoundWidth, rect.Y, RoundWidth, RoundHeight, 270, 90); gp.AddArc(rect.X + rect.Width – RoundWidth, rect.Y + rect.Height – RoundHeight, RoundWidth, RoundHeight, 0, 90);
gp.AddArc(rect.X, rect.Y + rect.Height – RoundHeight, RoundWidth, RoundHeight, 90, 90);
// Close the drawing and make sure that all the open line are closed
gp.CloseFigure();
// draw to graphics using provided pen
canvas.DrawPath(pen, gp);
}

2 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *