共用方式為


Graphics.DrawLine(const Pen*, const Point, const Point) method

Applies to: desktop apps only

The Graphics::DrawLine method draws a line that connects two points.

Syntax

Status DrawLine(
  [in]       const Pen *pen,
  [in, ref]  const Point &pt1,
  [in, ref]  const Point &pt2
);

Parameters

  • pen [in]
    Type: const Pen*

    Pointer to a pen that is used to draw the line.

  • pt1 [in, ref]
    Type: const Point

    Reference to a Point object that specifies the start of the line.

  • pt2 [in, ref]
    Type: const Point

    Reference to a Point object that specifies the end of the line.

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 line.

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

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

   // Create two Point objects that define the line.
   Point point1(100, 100);
   Point point2(500, 100);

   // Draw the line.
   graphics.DrawLine(&blackPen, point1, point2);

}

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

DrawLines Methods

Point

Using a Pen to Draw Lines and Rectangles

Pens, Lines, and Rectangles

 

 

Send comments about this topic to Microsoft

Build date: 3/6/2012