Skip to content

[API Proposal]: DrawRectangle should accept RectangleF as one of the overloads #62401

Closed
@medo64

Description

@medo64

Background and motivation

In Graphics class, FillRectangle contains the following 4 overloads:

  • public void FillRectangle(Brush brush, RectangleF rect)
  • public void FillRectangle(Brush brush, float x, float y, float width, float height)
  • public void FillRectangle(Brush brush, Rectangle rect)
  • public void FillRectangle(Brush brush, int x, int y, int width, int height)

However, DrawRectangle, contains only the following 3 overloads:

  • public void DrawRectangle(Pen pen, Rectangle rect)
  • public void DrawRectangle(Pen pen, float x, float y, float width, float height)
  • public void DrawRectangle(Pen pen, int x, int y, int width, int height)

In the interest of symmetry, I propose adding the "missing" RectangleF overload:

  • public void DrawRectangle(Pen pen, RectangleF rect)

During a development process one can quite often switch between DrawRectangle and FillRectangle API. This would allow to do so without changing the variables around, i.e. just by changing Fill into Draw and backward. Likewise, this would make drawing filled rectangles with outline in different color minutely easier.

API Proposal

namespace System.Drawing.Common
{
    public class Graphics
    {
        public void DrawRectangle(Pen pen, RectangleF rect);
    }
}

API Usage

API usage would be comparable to the existing API:

var rect = new RectangleF(...);
e.Graphics.FillRectangle(Brushes.Blue, rect);  // this works even now
e.Graphics.DrawRectangle(Pens.Red, rect);      // this would be a new overload

Alternative Designs

No response

Risks

Since method will just be a convenient way of calling already existing overload, risk is minimal if any.

Metadata

Metadata

Assignees

Labels

api-approvedAPI was approved in API review, it can be implementedarea-System.Drawingin-prThere is an active PR which will close this issue when it is merged

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions