Graphics.DrawLine 方法  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
绘制连接坐标对指定的两个点的线条。
重载
| DrawLine(Pen, Int32, Int32, Int32, Int32) | 绘制连接坐标对指定的两个点的线条。 | 
| DrawLine(Pen, Single, Single, Single, Single) | 绘制连接坐标对指定的两个点的线条。 | 
| DrawLine(Pen, Point, Point) | 绘制连接两个 Point 结构的线条。 | 
| DrawLine(Pen, PointF, PointF) | 绘制连接两个 PointF 结构的线条。 | 
DrawLine(Pen, Int32, Int32, Int32, Int32)
- Source:
- Graphics.cs
- Source:
- Graphics.cs
- Source:
- Graphics.cs
- Source:
- Graphics.cs
- Source:
- Graphics.cs
绘制连接坐标对指定的两个点的线条。
public:
 void DrawLine(System::Drawing::Pen ^ pen, int x1, int y1, int x2, int y2);public void DrawLine (System.Drawing.Pen pen, int x1, int y1, int x2, int y2);member this.DrawLine : System.Drawing.Pen * int * int * int * int -> unitPublic Sub DrawLine (pen As Pen, x1 As Integer, y1 As Integer, x2 As Integer, y2 As Integer)参数
- x1
- Int32
第一个点的 x 坐标。
- y1
- Int32
第一个点的 y 坐标。
- x2
- Int32
第二个点的 x 坐标。
- y2
- Int32
第二个点的 y 坐标。
例外
              pen
              null。
示例
下面的代码示例设计用于 Windows 窗体,它需要 PaintEventArgse,这是 Paint 事件处理程序的参数。 该代码执行以下操作:
- 创建黑色笔。 
- 创建线条终结点的坐标。 
- 将线条绘制到屏幕。 
public:
   void DrawLineInt( PaintEventArgs^ e )
   {
      // Create pen.
      Pen^ blackPen = gcnew Pen( Color::Black,3.0f );
      // Create coordinates of points that define line.
      int x1 = 100;
      int y1 = 100;
      int x2 = 500;
      int y2 = 100;
      // Draw line to screen.
      e->Graphics->DrawLine( blackPen, x1, y1, x2, y2 );
   }
public void DrawLineInt(PaintEventArgs e)
{
             
    // Create pen.
    Pen blackPen = new Pen(Color.Black, 3);
             
    // Create coordinates of points that define line.
    int x1 = 100;
    int y1 = 100;
    int x2 = 500;
    int y2 = 100;
             
    // Draw line to screen.
    e.Graphics.DrawLine(blackPen, x1, y1, x2, y2);
}
Public Sub DrawLineInt(ByVal e As PaintEventArgs)
    ' Create pen.
    Dim blackPen As New Pen(Color.Black, 3)
    ' Create coordinates of points that define line.
    Dim x1 As Integer = 100
    Dim y1 As Integer = 100
    Dim x2 As Integer = 500
    Dim y2 As Integer = 100
    ' Draw line to screen.
    e.Graphics.DrawLine(blackPen, x1, y1, x2, y2)
End Sub
注解
此方法绘制一条线,用于连接由 x1、y1、x2和 y2 参数指定的两个点。
另请参阅
适用于
DrawLine(Pen, Single, Single, Single, Single)
- Source:
- Graphics.cs
- Source:
- Graphics.cs
- Source:
- Graphics.cs
- Source:
- Graphics.cs
- Source:
- Graphics.cs
绘制连接坐标对指定的两个点的线条。
public:
 void DrawLine(System::Drawing::Pen ^ pen, float x1, float y1, float x2, float y2);public void DrawLine (System.Drawing.Pen pen, float x1, float y1, float x2, float y2);member this.DrawLine : System.Drawing.Pen * single * single * single * single -> unitPublic Sub DrawLine (pen As Pen, x1 As Single, y1 As Single, x2 As Single, y2 As Single)参数
- x1
- Single
第一个点的 x 坐标。
- y1
- Single
第一个点的 y 坐标。
- x2
- Single
第二个点的 x 坐标。
- y2
- Single
第二个点的 y 坐标。
例外
              pen
              null。
示例
下面的代码示例设计用于 Windows 窗体,它需要 PaintEventArgse,这是 Paint 事件处理程序的参数。 该代码执行以下操作:
- 创建黑色笔。 
- 创建线条终结点的坐标。 
- 将线条绘制到屏幕。 
public:
   void DrawLineFloat( PaintEventArgs^ e )
   {
      // Create pen.
      Pen^ blackPen = gcnew Pen( Color::Black,3.0f );
      // Create coordinates of points that define line.
      float x1 = 100.0F;
      float y1 = 100.0F;
      float x2 = 500.0F;
      float y2 = 100.0F;
      // Draw line to screen.
      e->Graphics->DrawLine( blackPen, x1, y1, x2, y2 );
   }
public void DrawLineFloat(PaintEventArgs e)
{
             
    // Create pen.
    Pen blackPen = new Pen(Color.Black, 3);
             
    // Create coordinates of points that define line.
    float x1 = 100.0F;
    float y1 = 100.0F;
    float x2 = 500.0F;
    float y2 = 100.0F;
             
    // Draw line to screen.
    e.Graphics.DrawLine(blackPen, x1, y1, x2, y2);
}
Public Sub DrawLineFloat(ByVal e As PaintEventArgs)
    ' Create pen.
    Dim blackPen As New Pen(Color.Black, 3)
    ' Create coordinates of points that define line.
    Dim x1 As Single = 100.0F
    Dim y1 As Single = 100.0F
    Dim x2 As Single = 500.0F
    Dim y2 As Single = 100.0F
    ' Draw line to screen.
    e.Graphics.DrawLine(blackPen, x1, y1, x2, y2)
End Sub
注解
此方法绘制一条线,用于连接由 x1、y1、x2和 y2 参数指定的两个点。
另请参阅
适用于
DrawLine(Pen, Point, Point)
- Source:
- Graphics.cs
- Source:
- Graphics.cs
- Source:
- Graphics.cs
- Source:
- Graphics.cs
- Source:
- Graphics.cs
绘制连接两个 Point 结构的线条。
public:
 void DrawLine(System::Drawing::Pen ^ pen, System::Drawing::Point pt1, System::Drawing::Point pt2);public void DrawLine (System.Drawing.Pen pen, System.Drawing.Point pt1, System.Drawing.Point pt2);member this.DrawLine : System.Drawing.Pen * System.Drawing.Point * System.Drawing.Point -> unitPublic Sub DrawLine (pen As Pen, pt1 As Point, pt2 As Point)参数
例外
              pen
              null。
示例
下面的代码示例设计用于 Windows 窗体,它需要 PaintEventArgse,这是 Paint 事件处理程序的参数。 该代码执行以下操作:
- 创建黑色笔。 
- 为线条的终结点创建点。 
- 将线条绘制到屏幕。 
public:
   void DrawLinePoint( PaintEventArgs^ e )
   {
      // Create pen.
      Pen^ blackPen = gcnew Pen( Color::Black,3.0f );
      // Create points that define line.
      Point point1 = Point(100,100);
      Point point2 = Point(500,100);
      // Draw line to screen.
      e->Graphics->DrawLine( blackPen, point1, point2 );
   }
public void DrawLinePoint(PaintEventArgs e)
{
             
    // Create pen.
    Pen blackPen = new Pen(Color.Black, 3);
             
    // Create points that define line.
    Point point1 = new Point(100, 100);
    Point point2 = new Point(500, 100);
             
    // Draw line to screen.
    e.Graphics.DrawLine(blackPen, point1, point2);
}
Public Sub DrawLinePoint(ByVal e As PaintEventArgs)
    ' Create pen.
    Dim blackPen As New Pen(Color.Black, 3)
    ' Create points that define line.
    Dim point1 As New Point(100, 100)
    Dim point2 As New Point(500, 100)
    ' Draw line to screen.
    e.Graphics.DrawLine(blackPen, point1, point2)
End Sub
另请参阅
适用于
DrawLine(Pen, PointF, PointF)
- Source:
- Graphics.cs
- Source:
- Graphics.cs
- Source:
- Graphics.cs
- Source:
- Graphics.cs
- Source:
- Graphics.cs
绘制连接两个 PointF 结构的线条。
public:
 void DrawLine(System::Drawing::Pen ^ pen, System::Drawing::PointF pt1, System::Drawing::PointF pt2);public void DrawLine (System.Drawing.Pen pen, System.Drawing.PointF pt1, System.Drawing.PointF pt2);member this.DrawLine : System.Drawing.Pen * System.Drawing.PointF * System.Drawing.PointF -> unitPublic Sub DrawLine (pen As Pen, pt1 As PointF, pt2 As PointF)参数
例外
              pen
              null。
示例
下面的代码示例设计用于 Windows 窗体,它需要 PaintEventArgse,这是 Paint 事件处理程序的参数。 该代码执行以下操作:
- 创建黑色笔。 
- 为线条的终结点创建点。 
- 将线条绘制到屏幕。 
public:
   void DrawLinePointF( PaintEventArgs^ e )
   {
      // Create pen.
      Pen^ blackPen = gcnew Pen( Color::Black,3.0f );
      
      // Create points that define line.
      PointF point1 = PointF(100.0F,100.0F);
      PointF point2 = PointF(500.0F,100.0F);
      // Draw line to screen.
      e->Graphics->DrawLine( blackPen, point1, point2 );
   }
public void DrawLinePointF(PaintEventArgs e)
{
             
    // Create pen.
    Pen blackPen = new Pen(Color.Black, 3);
             
    // Create points that define line.
    PointF point1 = new PointF(100.0F, 100.0F);
    PointF point2 = new PointF(500.0F, 100.0F);
             
    // Draw line to screen.
    e.Graphics.DrawLine(blackPen, point1, point2);
}
Public Sub DrawLinePointF(ByVal e As PaintEventArgs)
    ' Create pen.
    Dim blackPen As New Pen(Color.Black, 3)
    ' Create points that define line.
    Dim point1 As New PointF(100.0F, 100.0F)
    Dim point2 As New PointF(500.0F, 100.0F)
    ' Draw line to screen.
    e.Graphics.DrawLine(blackPen, point1, point2)
End Sub
注解
此方法绘制连接由 pt1 和 p2 参数指定的两个点的线条。