Geekpedia Programming Tutorials









Draw Rounded Corner Rectangles Using C#

Use the GDI library objects to draw rectangles that have rounded rectangles of a specified radius. The secret is to use a series of lines and arcs to form the rectangle as desired.

On Thursday, April 17th 2008 at 12:47 AM
By Andrei Pociu (View Profile)
*****   (Rated 5 with 1 votes)
Contextual Ads
More C# Resources
Advertisement
  1. public void DrawRoundRect(Graphics g, Pen p, float x, float y, float width, float height, float radius)
  2. {
  3.    GraphicsPath gp = new GraphicsPath();
  4.  
  5.    gp.AddLine(x + radius, y, x + width - (radius * 2), y); // Line
  6.    gp.AddArc(x + width - (radius * 2), y, radius * 2, radius * 2, 270, 90); // Corner
  7.    gp.AddLine(x + width, y + radius, x + width, y + height - (radius * 2)); // Line
  8.    gp.AddArc(x + width - (radius * 2), y + height - (radius * 2), radius * 2, radius * 2, 0, 90); // Corner
  9.    gp.AddLine(x + width - (radius * 2), y + height, x + radius, y + height); // Line
  10.    gp.AddArc(x, y + height - (radius * 2), radius * 2, radius * 2, 90, 90); // Corner
  11.    gp.AddLine(x, y + height - (radius * 2), x, y + radius); // Line
  12.    gp.AddArc(x, y, radius * 2, radius * 2, 180, 90); // Corner
  13.    gp.CloseFigure();
  14.  
  15.    g.DrawPath(p, gp);
  16.    gp.Dispose();
  17. }
Digg Digg It!     Del.icio.us Del.icio.us     Reddit Reddit     StumbleUpon StumbleIt     Newsvine Newsvine     Furl Furl     BlinkList BlinkList

Rate Rate this code snippet
Comment Current Comments
by Pradeep on Friday, April 25th 2008 at 06:39 AM

This code satisfies my requirements for my project and I need some thing more as

CODE OF FIND


Comment Comment on this tutorial
Name: Email:
Message:
Comment Related Source Code
There is no related code.

Comment Related Tutorials
There are no related tutorials.

Jobs C# Job Search
My skills include:
Enter a City:

Select a State:


Advanced Search >>
Latest Tech Bargains

Advertisement

Free Magazine Subscriptions

Today's Pictures

Today's Video

Other Resources

Latest Downloads

Latest Icons