Fill/Draw RoundedRectangle

public static void FillRoundedRectangle( this Graphics g, Pen pen, Brush brush, int x, int y, int width, int height, int radius )
		{
			Rectangle corner = new Rectangle( x, y, radius, radius );
			GraphicsPath path = new GraphicsPath( );
			path.AddArc( corner, 180, 90 );
			corner.X = x + width - radius;
			path.AddArc( corner, 270, 90 );
			corner.Y = y + height - radius;
			path.AddArc( corner, 0, 90 );
			corner.X = x;
			path.AddArc( corner, 90, 90 );
			path.CloseFigure( );

			g.FillPath( brush, path );

			if( pen != null )
			{
				g.DrawPath( pen, path );
			}
		}
Example:
protected override void OnPaint( PaintEventArgs e )
		{
			e.Graphics.FillRoundedRectangle( new Pen( Color.Black ), null, 0, 0, 200, 200, 12 );
		}

Description

C# extension to Fill and or Draw RoundedRectangle

Details

Double click on the code to select all.

 

;