Advertisement
HaLo2FrEeEk

Rounded Rectangle

Jan 11th, 2011
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.47 KB | None | 0 0
  1. /// <summary>
  2. /// Generate a curved path from a rectangle
  3. /// </summary>
  4. /// <param name="rec">The Rectangle to base the shape on</param>
  5. /// <param name="gp">The GraphicsPath to modify</param>
  6. /// <param name="radius">A float value to set the radius of the curve</param>
  7. /// <param name="inflate">The amount to inflate the Rectangle by (negative values will deflate)</param>
  8. public void makeCurve(RectangleF rec, ref GraphicsPath gp, float radius, float inflate)
  9. {
  10.     radius += inflate;
  11.     if (radius < 1)
  12.         radius = 1;
  13.  
  14.     inflate = inflate / 2;
  15.     rec.Width += inflate;
  16.     rec.Height += inflate;
  17.     rec.X -= inflate;
  18.     rec.Y -= inflate;
  19.  
  20.     gp.AddArc(new RectangleF(rec.Location, new SizeF(radius, radius)), 180, 90); // Left-Top
  21.     gp.AddLine(gp.GetLastPoint(), new PointF(rec.Width - radius, rec.Y)); // Top
  22.     gp.AddArc(new RectangleF(gp.GetLastPoint(), new SizeF(radius, radius)), -90, 90); // Right-Top
  23.     gp.AddLine(gp.GetLastPoint(), new PointF(rec.Width, rec.Height - radius)); // Right
  24.     gp.AddArc(new RectangleF(new PointF(gp.GetLastPoint().X - radius, gp.GetLastPoint().Y), new SizeF(radius, radius)), 0, 90); // Right-Bottom
  25.     gp.AddLine(gp.GetLastPoint(), new PointF(rec.X + radius, rec.Height)); // Bottom
  26.     gp.AddArc(new RectangleF(new PointF(rec.X, gp.GetLastPoint().Y - radius), new SizeF(radius, radius)), 90, 90); // Left-Bottom
  27.     gp.AddLine(gp.GetLastPoint(), new PointF(rec.X, rec.Y + radius)); // Left
  28.     gp.CloseFigure();
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement