Graphics.DrawLineとは? わかりやすく解説

Graphics.DrawLine メソッド (Pen, PointF, PointF)

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

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public Sub DrawLine ( _
    pen As Pen, _
    pt1 As PointF, _
    pt2 As PointF _
)
Dim instance As Graphics
Dim pen As Pen
Dim pt1 As PointF
Dim pt2 As PointF

instance.DrawLine(pen, pt1, pt2)
public void DrawLine (
    Pen pen,
    PointF pt1,
    PointF pt2
)
public:
void DrawLine (
    Pen^ pen, 
    PointF pt1, 
    PointF pt2
)
public void DrawLine (
    Pen pen, 
    PointF pt1, 
    PointF pt2
)
public function DrawLine (
    pen : Pen, 
    pt1 : PointF, 
    pt2 : PointF
)

パラメータ

pen

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

pt1

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

pt2

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

例外例外
例外の種類条件

ArgumentNullException

pen が null 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

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

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
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:
   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.get_Black(), 3);

    // Create points that define line.
    PointF point1 =  new PointF(100, 100);
    PointF point2 =  new PointF(500, 100);

    // Draw line to screen.
    e.get_Graphics().DrawLine(blackPen, point1, point2);
} //DrawLinePointF
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Graphics.DrawLine メソッド (Pen, Point, Point)

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

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public Sub DrawLine ( _
    pen As Pen, _
    pt1 As Point, _
    pt2 As Point _
)
Dim instance As Graphics
Dim pen As Pen
Dim pt1 As Point
Dim pt2 As Point

instance.DrawLine(pen, pt1, pt2)
public void DrawLine (
    Pen pen,
    Point pt1,
    Point pt2
)
public:
void DrawLine (
    Pen^ pen, 
    Point pt1, 
    Point pt2
)
public void DrawLine (
    Pen pen, 
    Point pt1, 
    Point pt2
)
public function DrawLine (
    pen : Pen, 
    pt1 : Point, 
    pt2 : Point
)

パラメータ

pen

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

pt1

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

pt2

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

例外例外
例外の種類条件

ArgumentNullException

pen が null 参照 (Visual Basic では Nothing) です。

使用例使用例

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

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
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:
   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.get_Black(), 3);
    
    // Create points that define line.
    Point point1 =  new Point(100, 100);
    Point point2 =  new Point(500, 100);
    
    // Draw line to screen.
    e.get_Graphics().DrawLine(blackPen, point1, point2);
} //DrawLinePoint
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Graphics.DrawLine メソッド

座標ペアで指定された 2 つの点を結ぶ直線を描画します。
オーバーロードの一覧オーバーロードの一覧

名前 説明
Graphics.DrawLine (Pen, Point, Point) 2 つの Point 構造体を接続する直線を描画します。
Graphics.DrawLine (Pen, PointF, PointF) 2 つの PointF 構造体を接続する直線を描画します。
Graphics.DrawLine (Pen, Int32, Int32, Int32, Int32) 座標ペアで指定された 2 つの点を結ぶ直線を描画します。

.NET Compact Framework によってサポートされています。

Graphics.DrawLine (Pen, Single, Single, Single, Single) 座標ペアで指定された 2 つの点を結ぶ直線を描画します。
参照参照

Graphics.DrawLine メソッド (Pen, Single, Single, Single, Single)

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

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public Sub DrawLine ( _
    pen As Pen, _
    x1 As Single, _
    y1 As Single, _
    x2 As Single, _
    y2 As Single _
)
Dim instance As Graphics
Dim pen As Pen
Dim x1 As Single
Dim y1 As Single
Dim x2 As Single
Dim y2 As Single

instance.DrawLine(pen, x1, y1, x2, y2)
public void DrawLine (
    Pen pen,
    float x1,
    float y1,
    float x2,
    float y2
)
public:
void DrawLine (
    Pen^ pen, 
    float x1, 
    float y1, 
    float x2, 
    float y2
)
public void DrawLine (
    Pen pen, 
    float x1, 
    float y1, 
    float x2, 
    float y2
)
public function DrawLine (
    pen : Pen, 
    x1 : float, 
    y1 : float, 
    x2 : float, 
    y2 : float
)

パラメータ

pen

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

x1

最初の点の x 座標。

y1

最初の点の y 座標。

x2

2 番目の点の x 座標。

y2

2 番目の点の y 座標。

例外例外
例外の種類条件

ArgumentNullException

pen が null 参照 (Visual Basic では Nothing) です。

解説解説

このメソッドは、x1、y1、x2、y2 の各パラメータで指定された 2 つの点を結ぶ直線を描画します。

使用例使用例

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

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
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:
   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.get_Black(), 3);

    // Create coordinates of points that define line.
    float x1 = 100;
    float y1 = 100;
    float x2 = 500;
    float y2 = 100;

    // Draw line to screen.
    e.get_Graphics().DrawLine(blackPen, x1, y1, x2, y2);
} //DrawLineFloat
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Graphics.DrawLine メソッド (Pen, Int32, Int32, Int32, Int32)

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

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public Sub DrawLine ( _
    pen As Pen, _
    x1 As Integer, _
    y1 As Integer, _
    x2 As Integer, _
    y2 As Integer _
)
Dim instance As Graphics
Dim pen As Pen
Dim x1 As Integer
Dim y1 As Integer
Dim x2 As Integer
Dim y2 As Integer

instance.DrawLine(pen, x1, y1, x2, y2)
public void DrawLine (
    Pen pen,
    int x1,
    int y1,
    int x2,
    int y2
)
public:
void DrawLine (
    Pen^ pen, 
    int x1, 
    int y1, 
    int x2, 
    int y2
)
public void DrawLine (
    Pen pen, 
    int x1, 
    int y1, 
    int x2, 
    int y2
)
public function DrawLine (
    pen : Pen, 
    x1 : int, 
    y1 : int, 
    x2 : int, 
    y2 : int
)

パラメータ

pen

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

x1

最初の点の x 座標。

y1

最初の点の y 座標。

x2

2 番目の点の x 座標。

y2

2 番目の点の y 座標。

例外例外
例外の種類条件

ArgumentNullException

pen が null 参照 (Visual Basic では Nothing) です。

解説解説

このメソッドは、x1、y1、x2、y2 の各パラメータで指定された 2 つの点を結ぶ直線を描画します。

使用例使用例

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

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
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:
   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.get_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.get_Graphics().DrawLine(blackPen, x1, y1, x2, y2);
} //DrawLineInt
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からGraphics.DrawLineを検索した結果を表示しています。
Weblioに収録されているすべての辞書からGraphics.DrawLineを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からGraphics.DrawLine を検索

英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「Graphics.DrawLine」の関連用語

Graphics.DrawLineのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Graphics.DrawLineのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS