Graphics.DrawRectangle Metoda

Definice

Nakreslí obdélník určený dvojicí souřadnic, šířkou a výškou.

Přetížení

DrawRectangle(Pen, Int32, Int32, Int32, Int32)

Nakreslí obdélník určený dvojicí souřadnic, šířkou a výškou.

DrawRectangle(Pen, Single, Single, Single, Single)

Nakreslí obdélník určený dvojicí souřadnic, šířkou a výškou.

DrawRectangle(Pen, RectangleF)

Nakreslí obrys zadaného obdélníku.

DrawRectangle(Pen, Rectangle)

Nakreslí obdélník určený strukturou Rectangle .

DrawRectangle(Pen, Int32, Int32, Int32, Int32)

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

Nakreslí obdélník určený dvojicí souřadnic, šířkou a výškou.

public:
 void DrawRectangle(System::Drawing::Pen ^ pen, int x, int y, int width, int height);
public void DrawRectangle (System.Drawing.Pen pen, int x, int y, int width, int height);
member this.DrawRectangle : System.Drawing.Pen * int * int * int * int -> unit
Public Sub DrawRectangle (pen As Pen, x As Integer, y As Integer, width As Integer, height As Integer)

Parametry

pen
Pen

Pen určuje barvu, šířku a styl obdélníku.

x
Int32

Souřadnice x levého horního rohu obdélníku, který chcete nakreslit.

y
Int32

Souřadnice y v levém horním rohu obdélníku, který chcete nakreslit.

width
Int32

Šířka obdélníku, který se má nakreslit.

height
Int32

Výška obdélníku, který chcete nakreslit.

Výjimky

pen je null.

Příklady

Následující příklad kódu je urč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ří pozici a velikost obdélníku.

  • Nakreslí obdélník na obrazovku.

public:
   void DrawRectangleInt( PaintEventArgs^ e )
   {
      // Create pen.
      Pen^ blackPen = gcnew Pen( Color::Black,3.0f );

      // Create location and size of rectangle.
      int x = 0;
      int y = 0;
      int width = 200;
      int height = 200;

      // Draw rectangle to screen.
      e->Graphics->DrawRectangle( blackPen, x, y, width, height );
   }
public void DrawRectangleInt(PaintEventArgs e)
{
             
    // Create pen.
    Pen blackPen = new Pen(Color.Black, 3);
             
    // Create location and size of rectangle.
    int x = 0;
    int y = 0;
    int width = 200;
    int height = 200;
             
    // Draw rectangle to screen.
    e.Graphics.DrawRectangle(blackPen, x, y, width, height);
}
Public Sub DrawRectangleInt(ByVal e As PaintEventArgs)

    ' Create pen.
    Dim blackPen As New Pen(Color.Black, 3)

    ' Create location and size of rectangle.
    Dim x As Integer = 0
    Dim y As Integer = 0
    Dim width As Integer = 200
    Dim height As Integer = 200

    ' Draw rectangle to screen.
    e.Graphics.DrawRectangle(blackPen, x, y, width, height)
End Sub

Poznámky

Informace o tom, jak nakreslit , najdete v RectangleFtématu DrawRectangles(Pen, RectangleF[]).

Platí pro

DrawRectangle(Pen, Single, Single, Single, Single)

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

Nakreslí obdélník určený dvojicí souřadnic, šířkou a výškou.

public:
 void DrawRectangle(System::Drawing::Pen ^ pen, float x, float y, float width, float height);
public void DrawRectangle (System.Drawing.Pen pen, float x, float y, float width, float height);
member this.DrawRectangle : System.Drawing.Pen * single * single * single * single -> unit
Public Sub DrawRectangle (pen As Pen, x As Single, y As Single, width As Single, height As Single)

Parametry

pen
Pen

Určuje Pen barvu, šířku a styl obdélníku.

x
Single

Souřadnice x levého horního rohu obdélníku, který chcete nakreslit.

y
Single

Souřadnice y v levém horním rohu obdélníku, který chcete nakreslit.

width
Single

Šířka obdélníku, který chcete nakreslit.

height
Single

Výška obdélníku, který chcete nakreslit.

Výjimky

pen je null.

Příklady

Následující příklad kódu je urč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ří pozici a velikost obdélníku.

  • Nakreslí obdélník na obrazovku.

public:
   void DrawRectangleFloat( PaintEventArgs^ e )
   {
      // Create pen.
      Pen^ blackPen = gcnew Pen( Color::Black,3.0f );

      // Create location and size of rectangle.
      float x = 0.0F;
      float y = 0.0F;
      float width = 200.0F;
      float height = 200.0F;

      // Draw rectangle to screen.
      e->Graphics->DrawRectangle( blackPen, x, y, width, height );
   }
public void DrawRectangleFloat(PaintEventArgs e)
{
             
    // Create pen.
    Pen blackPen = new Pen(Color.Black, 3);
             
    // Create location and size of rectangle.
    float x = 0.0F;
    float y = 0.0F;
    float width = 200.0F;
    float height = 200.0F;
             
    // Draw rectangle to screen.
    e.Graphics.DrawRectangle(blackPen, x, y, width, height);
}
Public Sub DrawRectangleFloat(ByVal e As PaintEventArgs)

    ' Create pen.
    Dim blackPen As New Pen(Color.Black, 3)

    ' Create location and size of rectangle.
    Dim x As Single = 0.0F
    Dim y As Single = 0.0F
    Dim width As Single = 200.0F
    Dim height As Single = 200.0F

    ' Draw rectangle to screen.
    e.Graphics.DrawRectangle(blackPen, x, y, width, height)
End Sub

Poznámky

Informace o tom, jak nakreslit , najdete v RectangleFtématu DrawRectangles(Pen, RectangleF[]).

Platí pro

DrawRectangle(Pen, RectangleF)

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

Nakreslí obrys zadaného obdélníku.

public:
 void DrawRectangle(System::Drawing::Pen ^ pen, System::Drawing::RectangleF rect);
public void DrawRectangle (System.Drawing.Pen pen, System.Drawing.RectangleF rect);
member this.DrawRectangle : System.Drawing.Pen * System.Drawing.RectangleF -> unit
Public Sub DrawRectangle (pen As Pen, rect As RectangleF)

Parametry

pen
Pen

Pero, které určuje barvu, šířku a styl obdélníku.

rect
RectangleF

Obdélník, který chcete nakreslit.

Platí pro

DrawRectangle(Pen, Rectangle)

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

Nakreslí obdélník určený strukturou Rectangle .

public:
 void DrawRectangle(System::Drawing::Pen ^ pen, System::Drawing::Rectangle rect);
public void DrawRectangle (System.Drawing.Pen pen, System.Drawing.Rectangle rect);
member this.DrawRectangle : System.Drawing.Pen * System.Drawing.Rectangle -> unit
Public Sub DrawRectangle (pen As Pen, rect As Rectangle)

Parametry

pen
Pen

Určuje Pen barvu, šířku a styl obdélníku.

rect
Rectangle

Struktura Rectangle , která představuje obdélník, který chcete nakreslit.

Výjimky

pen je null.

Příklady

Následující příklad kódu je urč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ří obdélník.

  • Nakreslí obdélník na obrazovku.

public:
   void DrawRectangleRectangle( PaintEventArgs^ e )
   {
      // Create pen.
      Pen^ blackPen = gcnew Pen( Color::Black,3.0f );

      // Create rectangle.
      Rectangle rect = Rectangle(0,0,200,200);

      // Draw rectangle to screen.
      e->Graphics->DrawRectangle( blackPen, rect );
   }
public void DrawRectangleRectangle(PaintEventArgs e)
{
             
    // Create pen.
    Pen blackPen = new Pen(Color.Black, 3);
             
    // Create rectangle.
    Rectangle rect = new Rectangle(0, 0, 200, 200);
             
    // Draw rectangle to screen.
    e.Graphics.DrawRectangle(blackPen, rect);
}
Public Sub DrawRectangleRectangle(ByVal e As PaintEventArgs)

    ' Create pen.
    Dim blackPen As New Pen(Color.Black, 3)

    ' Create rectangle.
    Dim rect As New Rectangle(0, 0, 200, 200)

    ' Draw rectangle to screen.
    e.Graphics.DrawRectangle(blackPen, rect)
End Sub

Poznámky

Informace o tom, jak nakreslit , najdete v RectangleFtématu DrawRectangles(Pen, RectangleF[]).

Platí pro