Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support rounded rectangle in Graphics class #9001

Closed
ghost opened this issue Apr 19, 2023 · 3 comments · Fixed by #10926
Closed

Support rounded rectangle in Graphics class #9001

ghost opened this issue Apr 19, 2023 · 3 comments · Fixed by #10926
Assignees
Labels
api-approved (4) API was approved in API review, it can be implemented area-System.Drawing System.Drawing issues 🚧 work in progress Work that is current in progress
Milestone

Comments

@ghost
Copy link

ghost commented Apr 19, 2023

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

@ghost ghost added api-suggestion (1) Early API idea and discussion, it is NOT ready for implementation untriaged The team needs to look at this issue in the next triage labels Apr 19, 2023
@RussKie
Copy link
Member

RussKie commented Apr 19, 2023

Kind of feels like you're asking for CreateRoundRectRgn...

@ghost
Copy link
Author

ghost commented Apr 19, 2023

Yes, it looks like this is a feature that Win32 already supports, but it's not currently included in WinForms.

@JeremyKuhne JeremyKuhne self-assigned this Apr 19, 2023
@JeremyKuhne JeremyKuhne added the area-System.Drawing System.Drawing issues label Apr 19, 2023
@merriemcgaw merriemcgaw removed the untriaged The team needs to look at this issue in the next triage label May 3, 2023
@merriemcgaw merriemcgaw added this to the .NET 9.0 milestone Jan 24, 2024
@JeremyKuhne JeremyKuhne added api-ready-for-review (2) API is ready for formal API review; applied by the issue owner and removed api-suggestion (1) Early API idea and discussion, it is NOT ready for implementation labels Jan 30, 2024
@bartonjs
Copy link
Member

  • Based on the naming from GDI and from WPF, Size corner => Size radius.
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 radius);
+    public void DrawRoundedRectangle(System.Drawing.Pen pen, System.Drawing.RectangleF rect, SizeF radius);
+    public void FillRoundedRectangle(System.Drawing.Brush brush, System.Drawing.Rectangle rect, Size radius);
+    public void FillRoundedRectangle(System.Drawing.Brush brush, System.Drawing.RectangleF rect, SizeF radius);
}

namespace System.Drawing.Drawing2D;

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

@bartonjs bartonjs added api-approved (4) API was approved in API review, it can be implemented and removed api-ready-for-review (2) API is ready for formal API review; applied by the issue owner labels Feb 20, 2024
@dotnet-policy-service dotnet-policy-service bot added the 🚧 work in progress Work that is current in progress label Feb 21, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Mar 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-approved (4) API was approved in API review, it can be implemented area-System.Drawing System.Drawing issues 🚧 work in progress Work that is current in progress
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants