Graphics.DrawRectangle Método

Definição

Desenha um retângulo especificado por um par de coordenadas, uma largura e uma altura.

Sobrecargas

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

Desenha um retângulo especificado por um par de coordenadas, uma largura e uma altura.

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

Desenha um retângulo especificado por um par de coordenadas, uma largura e uma altura.

DrawRectangle(Pen, RectangleF)

Desenha a estrutura de tópicos do retângulo especificado.

DrawRectangle(Pen, Rectangle)

Desenha um retângulo especificado por uma estrutura Rectangle.

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

Origem:
Graphics.cs
Origem:
Graphics.cs
Origem:
Graphics.cs

Desenha um retângulo especificado por um par de coordenadas, uma largura e uma altura.

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)

Parâmetros

pen
Pen

Pen que determina a cor, a largura e o estilo do retângulo.

x
Int32

A coordenada X do canto superior esquerdo do retângulo a ser desenhado.

y
Int32

A coordenada y do canto superior esquerdo do retângulo a ser desenhada.

width
Int32

A largura do retângulo a ser desenhado.

height
Int32

A altura do retângulo a ser desenhado.

Exceções

pen é null.

Exemplos

O exemplo de código a seguir foi projetado para uso com Windows Forms e requer PaintEventArgse, que é um parâmetro do Paint manipulador de eventos. O código executa as seguintes ações:

  • Cria uma caneta preta.

  • Cria a posição e o tamanho de um retângulo.

  • Desenha o retângulo na tela.

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

Comentários

Para obter informações sobre como desenhar um RectangleF, consulte DrawRectangles(Pen, RectangleF[]).

Aplica-se a

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

Origem:
Graphics.cs
Origem:
Graphics.cs
Origem:
Graphics.cs

Desenha um retângulo especificado por um par de coordenadas, uma largura e uma altura.

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)

Parâmetros

pen
Pen

Um Pen que determina a cor, a largura e o estilo do retângulo.

x
Single

A coordenada X do canto superior esquerdo do retângulo a ser desenhado.

y
Single

A coordenada y do canto superior esquerdo do retângulo a ser desenhada.

width
Single

A largura do retângulo a ser desenhada.

height
Single

A altura do retângulo a ser desenhada.

Exceções

pen é null.

Exemplos

O exemplo de código a seguir foi projetado para uso com Windows Forms e requer PaintEventArgse, que é um parâmetro do Paint manipulador de eventos. O código executa as seguintes ações:

  • Cria uma caneta preta.

  • Cria a posição e o tamanho de um retângulo.

  • Desenha o retângulo na tela.

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

Comentários

Para obter informações sobre como desenhar um RectangleF, consulte DrawRectangles(Pen, RectangleF[]).

Aplica-se a

DrawRectangle(Pen, RectangleF)

Origem:
Graphics.cs
Origem:
Graphics.cs
Origem:
Graphics.cs

Desenha a estrutura de tópicos do retângulo especificado.

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)

Parâmetros

pen
Pen

Uma caneta que determina a cor, a largura e o estilo do retângulo.

rect
RectangleF

O retângulo a ser desenhado.

Aplica-se a

DrawRectangle(Pen, Rectangle)

Origem:
Graphics.cs
Origem:
Graphics.cs
Origem:
Graphics.cs

Desenha um retângulo especificado por uma estrutura 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)

Parâmetros

pen
Pen

Um Pen que determina a cor, a largura e o estilo do retângulo.

rect
Rectangle

Uma estrutura Rectangle que representa o retângulo a ser desenhado.

Exceções

pen é null.

Exemplos

O exemplo de código a seguir foi projetado para uso com Windows Forms e requer PaintEventArgse, que é um parâmetro do Paint manipulador de eventos. O código executa as seguintes ações:

  • Cria uma caneta preta.

  • Cria um retângulo.

  • Desenha o retângulo na tela.

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

Comentários

Para obter informações sobre como desenhar um RectangleF, consulte DrawRectangles(Pen, RectangleF[]).

Aplica-se a