Graphics.DrawLine メソッド

定義

座標ペアで指定された 2 つの点を結ぶ直線を描画します。

オーバーロード

DrawLine(Pen, Int32, Int32, Int32, Int32)

座標ペアで指定された 2 つの点を結ぶ直線を描画します。

DrawLine(Pen, Single, Single, Single, Single)

座標ペアで指定された 2 つの点を結ぶ直線を描画します。

DrawLine(Pen, Point, Point)

2 つの Point 構造体を接続する直線を描画します。

DrawLine(Pen, PointF, PointF)

2 つの PointF 構造体を接続する直線を描画します。

DrawLine(Pen, Int32, Int32, Int32, Int32)

ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs

座標ペアで指定された 2 つの点を結ぶ直線を描画します。

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 -> unit
Public Sub DrawLine (pen As Pen, x1 As Integer, y1 As Integer, x2 As Integer, y2 As Integer)

パラメーター

pen
Pen

直線の色、幅、およびスタイルを決定する Pen

x1
Int32

最初の点の x 座標。

y1
Int32

最初の点の y 座標。

x2
Int32

2 番目の点の x 座標。

y2
Int32

2 番目の点の y 座標。

例外

pennullです。

次のコード例は、Windows フォームで使用するように設計されており、イベント ハンドラーのPaintパラメーターである が必要PaintEventArgseです。 コードは、次のアクションを実行します。

  • 黒いペンを作成します。

  • 線の端点の座標を作成します。

  • 画面に線を描画します。

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

注釈

このメソッドは、および パラメーターで指定された 2 つのポイントをx1y1x2結ぶ線をy2描画します。

こちらもご覧ください

適用対象

DrawLine(Pen, Single, Single, Single, Single)

ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs

座標ペアで指定された 2 つの点を結ぶ直線を描画します。

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 -> unit
Public Sub DrawLine (pen As Pen, x1 As Single, y1 As Single, x2 As Single, y2 As Single)

パラメーター

pen
Pen

直線の色、幅、およびスタイルを決定する Pen

x1
Single

最初の点の x 座標。

y1
Single

最初の点の y 座標。

x2
Single

2 番目の点の x 座標。

y2
Single

2 番目の点の y 座標。

例外

pennullです。

次のコード例は、Windows フォームで使用するように設計されており、イベント ハンドラーのPaintパラメーターである が必要PaintEventArgseです。 コードは、次のアクションを実行します。

  • 黒いペンを作成します。

  • 線の端点の座標を作成します。

  • 画面に線を描画します。

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

注釈

このメソッドは、および パラメーターで指定された 2 つのポイントをx1y1x2結ぶ線をy2描画します。

こちらもご覧ください

適用対象

DrawLine(Pen, Point, Point)

ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs

2 つの 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 -> unit
Public Sub DrawLine (pen As Pen, pt1 As Point, pt2 As Point)

パラメーター

pen
Pen

直線の色、幅、およびスタイルを決定する Pen

pt1
Point

接続する最初の点を表す Point 構造体。

pt2
Point

接続する 2 番目の点を表す Point 構造体。

例外

pennullです。

次のコード例は、Windows フォームで使用するように設計されており、イベント ハンドラーのPaintパラメーターである が必要PaintEventArgseです。 コードは、次のアクションを実行します。

  • 黒いペンを作成します。

  • 線の端点のポイントを作成します。

  • 画面に線を描画します。

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)

ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs

2 つの 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 -> unit
Public Sub DrawLine (pen As Pen, pt1 As PointF, pt2 As PointF)

パラメーター

pen
Pen

直線の色、幅、およびスタイルを決定する Pen

pt1
PointF

接続する最初の点を表す PointF 構造体。

pt2
PointF

接続する 2 番目の点を表す PointF 構造体。

例外

pennullです。

次のコード例は、Windows フォームで使用するように設計されており、イベント ハンドラーのPaintパラメーターである が必要PaintEventArgseです。 コードは、次のアクションを実行します。

  • 黒いペンを作成します。

  • 線の端点のポイントを作成します。

  • 画面に線を描画します。

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

注釈

このメソッドは、 パラメーターと p2 パラメーターで指定された 2 つの点を結ぶ線をpt1描画します。

こちらもご覧ください

適用対象