Draw Rounded Rectangle menggunakan GDI+ di C#

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);
}

Related Posts

Gempa Lagi
Weleh... gempa euy. Waktu sedang kongkow dengan temen selepas maghrib, tiba-tiba terasa kepala kok jadi...
Hampir Tertipu
Sore tadi istriku mengabari berita yang cukup mengagetkan. Walaupun ada kecurigaan karena beberapa kejanggalan,...
Sutiyoso for President 2009
Waw... bravo. Terus terang kayanya baru kali ini saya melihat ada seseorang yang dengan lantang mengatakan...
Bayar Tol Secara Elektronik
Bila anda sering menggunakan jalur tol seperti saya ketika di Indonesia sepertinya mulai merasa perlu...
Leave a comment

2 Comments.

  1. Kalau rounded polygon gimana ya Pak?

  2. bapak saia mau tanya, Data Binding itu apa?
    Tepatnya pada Dynamic HTML.
    Terima Kasih

Leave a Reply

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

*


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>