Graphics.DrawRectangle Méthode

Définition

Dessine un rectangle spécifié par une paire de coordonnées, une largeur et une hauteur.

Surcharges

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

Dessine un rectangle spécifié par une paire de coordonnées, une largeur et une hauteur.

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

Dessine un rectangle spécifié par une paire de coordonnées, une largeur et une hauteur.

DrawRectangle(Pen, RectangleF)

Dessine le contour du rectangle spécifié.

DrawRectangle(Pen, Rectangle)

Dessine un rectangle spécifié par une structure Rectangle.

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

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

Dessine un rectangle spécifié par une paire de coordonnées, une largeur et une hauteur.

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)

Paramètres

pen
Pen

Pen qui détermine la couleur, la largeur et le style du rectangle.

x
Int32

Coordonnée x de l'angle supérieur gauche du rectangle à dessiner.

y
Int32

Coordonnée y de l'angle supérieur gauche du rectangle à dessiner.

width
Int32

Largeur du rectangle à dessiner.

height
Int32

Hauteur du rectangle à dessiner.

Exceptions

pen a la valeur null.

Exemples

L’exemple de code suivant est conçu pour être utilisé avec Windows Forms et nécessite PaintEventArgse, qui est un paramètre du Paint gestionnaire d’événements. Le code effectue les actions suivantes :

  • Crée un stylet noir.

  • Crée la position et la taille d’un rectangle.

  • Dessine le rectangle à l’écran.

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

Remarques

Pour plus d’informations sur la façon de dessiner un RectangleF, consultez DrawRectangles(Pen, RectangleF[]).

S’applique à

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

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

Dessine un rectangle spécifié par une paire de coordonnées, une largeur et une hauteur.

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)

Paramètres

pen
Pen

Pen qui détermine la couleur, la largeur et le style du rectangle.

x
Single

Coordonnée x de l'angle supérieur gauche du rectangle à dessiner.

y
Single

Coordonnée y de l'angle supérieur gauche du rectangle à dessiner.

width
Single

Largeur du rectangle à dessiner.

height
Single

Hauteur du rectangle à dessiner.

Exceptions

pen a la valeur null.

Exemples

L’exemple de code suivant est conçu pour être utilisé avec Windows Forms et nécessite PaintEventArgse, qui est un paramètre du Paint gestionnaire d’événements. Le code effectue les actions suivantes :

  • Crée un stylet noir.

  • Crée la position et la taille d’un rectangle.

  • Dessine le rectangle à l’écran.

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

Remarques

Pour plus d’informations sur la façon de dessiner un RectangleF, consultez DrawRectangles(Pen, RectangleF[]).

S’applique à

DrawRectangle(Pen, RectangleF)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

Dessine le contour du rectangle spécifié.

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)

Paramètres

pen
Pen

Stylet qui détermine la couleur, la largeur et le style du rectangle.

rect
RectangleF

Rectangle à dessiner.

S’applique à

DrawRectangle(Pen, Rectangle)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

Dessine un rectangle spécifié par une structure 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)

Paramètres

pen
Pen

Pen qui détermine la couleur, la largeur et le style du rectangle.

rect
Rectangle

Structure Rectangle qui représente le rectangle à dessiner.

Exceptions

pen a la valeur null.

Exemples

L’exemple de code suivant est conçu pour être utilisé avec Windows Forms et nécessite PaintEventArgse, qui est un paramètre du Paint gestionnaire d’événements. Le code effectue les actions suivantes :

  • Crée un stylet noir.

  • Crée un rectangle.

  • Dessine le rectangle à l’écran.

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

Remarques

Pour plus d’informations sur la façon de dessiner un RectangleF, consultez DrawRectangles(Pen, RectangleF[]).

S’applique à