Graphics.DrawRectangle(const Pen*, INT, INT, INT, INT) method

Applies to: desktop apps only

The Graphics::DrawRectangle method draws a rectangle.

Syntax

Status DrawRectangle(
  [in]  const Pen *pen,
  [in]  INT x,
  [in]  INT y,
  [in]  INT width,
  [in]  INT height
);

Parameters

  • pen [in]
    Type: const Pen*

    Pointer to a Pen that is used to draw the rectangle.

  • x [in]
    Type: INT

    Integer that specifies the x-coordinate of the upper-left corner of the rectangle.

  • y [in]
    Type: INT

    Integer that specifies the y-coordinate of the upper-left corner of the rectangle.

  • width [in]
    Type: INT

    Integer that specifies the width of the rectangle.

  • height [in]
    Type: INT

    Integer that specifies the height of the rectangle.

Return value

Type:

Type: Status****

If the method succeeds, it returns Ok, which is an element of the Status enumeration.

If the method fails, it returns one of the other elements of the Status enumeration.

Examples

The following example draws a rectangle.

VOID Example_DrawRectangle3(HDC hdc)
{
   Graphics graphics(hdc);

   // Create a Pen object.
   Pen blackPen(Color(255, 0, 0, 0), 3);

   // Define the rectangle.
   int x = 0;
   int y = 0;
   int width = 200;
   int height = 200;

   // Draw the rectangle.
   graphics.DrawRectangle(&blackPen, x, y, width, height);
}

Requirements

Minimum supported client

Windows XP, Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Product

GDI+ 1.0

Header

Gdiplusgraphics.h (include Gdiplus.h)

Library

Gdiplus.lib

DLL

Gdiplus.dll

See also

Graphics

DrawRectangles Methods

FillRectangle Methods

Rect

Using a Pen to Draw Lines and Rectangles

Pens, Lines, and Rectangles

 

 

Send comments about this topic to Microsoft

Build date: 3/6/2012