Skip to content

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

Closed

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.

Activity

  1. added
    api-suggestion
    on Dec 4, 2021
  2. ghost added
    untriaged
    on Dec 4, 2021
  3. removed
    untriaged
    on Dec 6, 2021
  4. safern commented on Dec 6, 2021

    @safern
    Member

    Makes sense to add this overload to be consistent with what we have on other APIs, i.e Graphics.FillRectangle.

    Marking it as api-ready-for-review to discuss it on the review meeting.

  5. added
    api-ready-for-review
    on Dec 6, 2021
  6. terrajobst commented on Dec 14, 2021

    @terrajobst
    Contributor

    Video

    • Seems like a no-brainer
      • Are there any other? Seems like FillPie would be in the same category.
    namespace System.Drawing.Common
    {
        public partial class Graphics
        {
            public void DrawRectangle(Pen pen, RectangleF rect);
            public void FillPie(Brush brush, RectangleF rect, float startAngle, float sweepAngle);
        }
    }
  7. added
    api-approved
    and removed
    api-ready-for-review
    on Dec 14, 2021
  8. medo64 commented on Dec 15, 2021

    @medo64
    ContributorAuthor
    • Seems like a no-brainer
      • Are there any other? Seems like FillPie would be in the same category.

    Agreed; missed that one. I believe FillPie is the only one missing RectangleF but having Rectangle. There is a DrawIcon but there I believe having just Rectangle is appropriate.

  9. medo64 commented on Dec 15, 2021

    @medo64
    ContributorAuthor

    I did ask for pull request to be reopened (yes, I did things slightly out of order). Once that happens I will push commit for FillPie in addition to DrawRectangle that was already part of original pull request.

  10. deeprobin commented on Dec 21, 2021

    @deeprobin
    Contributor

    Please tag this with "in pr" 😄 thank you

  11. added
    in-pr
    on Jan 3, 2022
  12. removed
    api-suggestion
    on Mar 7, 2022
  13. jeffhandley commented on Mar 16, 2022

    @jeffhandley
    Member

    This was completed in #62385

  14. added this to the 7.0.0 milestone on Mar 16, 2022
  15. ghost locked as resolved and limited conversation to collaborators on Apr 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api-approvedarea-System.Drawingin-pr

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions