Graphics.DrawLine Metoda

Definice

Nakreslí čáru spojující dva body určené dvojicemi souřadnic.

Přetížení

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

Nakreslí čáru spojující dva body určené dvojicemi souřadnic.

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

Nakreslí čáru spojující dva body určené dvojicemi souřadnic.

DrawLine(Pen, Point, Point)

Nakreslí čáru spojující dvě Point struktury.

DrawLine(Pen, PointF, PointF)

Nakreslí čáru spojující dvě PointF struktury.

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

Zdroj:
Graphics.cs
Zdroj:
Graphics.cs
Zdroj:
Graphics.cs

Nakreslí čáru spojující dva body určené dvojicemi souřadnic.

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)

Parametry

pen
Pen

Pen určuje barvu, šířku a styl čáry.

x1
Int32

Souřadnice x prvního bodu.

y1
Int32

Souřadnice y prvního bodu.

x2
Int32

Souřadnice x druhého bodu.

y2
Int32

Souřadnice y druhého bodu.

Výjimky

pen je null.

Příklady

Následující příklad kódu je navržený pro použití s model Windows Forms a vyžaduje PaintEventArgse, což je parametr obslužné rutiny Paint události. Kód provede následující akce:

  • Vytvoří černé pero.

  • Vytvoří souřadnice koncových bodů řádku.

  • Nakreslí čáru na obrazovku.

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

Poznámky

Tato metoda nakreslí čáru spojující dva body určené x1parametry , y1, x2a y2 .

Viz také

Platí pro

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

Zdroj:
Graphics.cs
Zdroj:
Graphics.cs
Zdroj:
Graphics.cs

Nakreslí čáru spojující dva body určené dvojicemi souřadnic.

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)

Parametry

pen
Pen

Pen určuje barvu, šířku a styl čáry.

x1
Single

Souřadnice x prvního bodu.

y1
Single

Souřadnice y prvního bodu.

x2
Single

Souřadnice x druhého bodu.

y2
Single

Souřadnice y druhého bodu.

Výjimky

pen je null.

Příklady

Následující příklad kódu je navržený pro použití s model Windows Forms a vyžaduje PaintEventArgse, což je parametr obslužné rutiny Paint události. Kód provede následující akce:

  • Vytvoří černé pero.

  • Vytvoří souřadnice koncových bodů řádku.

  • Nakreslí čáru na obrazovku.

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

Poznámky

Tato metoda nakreslí čáru spojující dva body určené x1parametry , y1, x2a y2 .

Viz také

Platí pro

DrawLine(Pen, Point, Point)

Zdroj:
Graphics.cs
Zdroj:
Graphics.cs
Zdroj:
Graphics.cs

Nakreslí čáru spojující dvě Point struktury.

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)

Parametry

pen
Pen

Pen určuje barvu, šířku a styl čáry.

pt1
Point

Point , která představuje první bod, který se má spojit.

pt2
Point

Point struktury, která představuje druhý bod, který se má spojit.

Výjimky

pen je null.

Příklady

Následující příklad kódu je navržený pro použití s model Windows Forms a vyžaduje PaintEventArgse, což je parametr obslužné rutiny Paint události. Kód provede následující akce:

  • Vytvoří černé pero.

  • Vytvoří body pro koncové body řádku.

  • Nakreslí čáru na obrazovku.

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

Viz také

Platí pro

DrawLine(Pen, PointF, PointF)

Zdroj:
Graphics.cs
Zdroj:
Graphics.cs
Zdroj:
Graphics.cs

Nakreslí čáru spojující dvě PointF struktury.

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)

Parametry

pen
Pen

Pen určuje barvu, šířku a styl čáry.

pt1
PointF

PointF , která představuje první bod, který se má spojit.

pt2
PointF

PointF struktury, která představuje druhý bod, který se má spojit.

Výjimky

pen je null.

Příklady

Následující příklad kódu je navržený pro použití s model Windows Forms a vyžaduje PaintEventArgse, což je parametr obslužné rutiny Paint události. Kód provede následující akce:

  • Vytvoří černé pero.

  • Vytvoří body pro koncové body řádku.

  • Nakreslí čáru na obrazovku.

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

Poznámky

Tato metoda nakreslí čáru spojující dva body určené pt1 parametry a p2 .

Viz také

Platí pro