Search code examples
winapigdi+gdi

GDI+ equivalent of GDI Rectangle


What is the GDI+ equivalent of the GDI Rectangle function?

enter image description here

| Library | Outline       | Fill interior | Both        |
|---------|---------------|---------------|-------------|
| GDI     | FrameRect     | FillRect      | Rectangle   |
| GDI+    | DrawRectangle | FillRectangle | ?           |

Solution

  • GDI+ version of Rectangle

    Delphi:

    class procedure TGDIPlusHelper.Rectangle(g: TGPGraphics; OutlinePen: TGPPen; InteriorFillBrush: TGPBrush; x, y, width, height: Single);
    begin
        //GDI has Rectangle.
        //GDI+ we simulate it with FillRectangle followed by DrawRectangle
        g.FillRectangle(InteriorFillBrush, x, y, width, height);
        g.DrawRectangle(OutlinePen, x, y, width, height);
    end;
    

    C#:

    void Rectangle(Graphics g, Pen outlinePen; Brush interiorFillBrush, Single x, Single y, Single width, Single height)
    {
        //GDI has Rectangle.
        //GDI+ we simulate it with FillRectangle followed by DrawRectangle
        g.FillRectangle(InteriorFillBrush, x, y, width, height);
        g.DrawRectangle(OutlinePen, x, y, width, height);
    }