Skip to content

Support rounded rectangle in Graphics class #9001

@ghost

Description

Background and motivation

In modern interfaces, rounded rectangles are used in many places instead of right-angled rectangles, such as github buttons and labels.

GDI has RoundRect, but GDI+ doesn't have a direct equivalent. We can, however, do the necessary path generation in GDI+ to implement this fairly common request.

001

The current Graphics class provides Graphics.DrawRectangle and Graphics.FillRectangle to support drawing rectangles, but currently there is no corresponding method for drawing rounded rectangles.

API Proposal

namespace System.Drawing;

public class Graphics
{
     public void DrawRectangle(System.Drawing.Pen pen, System.DrawingRectangle rect);
     // ...
+    public void DrawRoundedRectangle(System.Drawing.Pen pen, System.Drawing.Rectangle rect, Size corner);
+    public void DrawRoundedRectangle(System.Drawing.Pen pen, System.Drawing.RectangleF rect, SizeF corner);
+    public void FillRoundedRectangle(System.Drawing.Brush brush, System.Drawing.Rectangle rect, Size corner);
+    public void FillRoundedRectangle(System.Drawing.Brush brush, System.Drawing.RectangleF rect, SizeF corner);
}

namespace System.Drawing.Drawing2D;

public class GraphicsPath
{
     public void AddRectangle(Rectangle rect);
     // ...
+    public void AddRoundedRectangle(Rectangle rect, Size corner);
+    public void AddRoundedRectangle(RectangleF rect, SizeF corner);
}

API Usage

graphics.DrawRoundedRectangle(new Pen(Color.Black), new Rectangle(0, 0, 100, 100), new Size(5, 5));
graphics.FillRoundedRectangle(new SolidBrush(Color.Black), new Rectangle(0, 0, 100, 100), new Size(5, 5));

Metadata

Metadata

Labels

🚧 work in progressWork that is current in progressapi-approved(4) API was approved in API review, it can be implementedarea-System.DrawingSystem.Drawing issues

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions