Graphics.DrawRectangle Metodo

Definizione

Disegna un rettangolo specificato da una coppia di coordinate, una larghezza e un'altezza.

Overload

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

Disegna un rettangolo specificato da una coppia di coordinate, una larghezza e un'altezza.

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

Disegna un rettangolo specificato da una coppia di coordinate, una larghezza e un'altezza.

DrawRectangle(Pen, RectangleF)

Disegna la struttura del rettangolo specificato.

DrawRectangle(Pen, Rectangle)

Disegna un rettangolo specificato da una struttura Rectangle.

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

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

Disegna un rettangolo specificato da una coppia di coordinate, una larghezza e un'altezza.

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)

Parametri

pen
Pen

Oggetto Pen che determina il colore, la larghezza e lo stile dell'ellisse.

x
Int32

Coordinata X dell'angolo superiore sinistro del rettangolo da disegnare.

y
Int32

Coordinata Y dell'angolo superiore sinistro del rettangolo da disegnare.

width
Int32

Larghezza del rettangolo da disegnare.

height
Int32

Altezza del rettangolo da disegnare.

Eccezioni

pen è null.

Esempio

L'esempio di codice seguente è progettato per l'uso con Windows Forms e richiede PaintEventArgse, che è un parametro del Paint gestore eventi. Il codice esegue le azioni seguenti:

  • Crea una penna nera.

  • Crea la posizione e le dimensioni di un rettangolo.

  • Disegna il rettangolo sullo schermo.

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

Commenti

Per informazioni su come disegnare un RectangleFoggetto , vedere DrawRectangles(Pen, RectangleF[]).

Si applica a

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

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

Disegna un rettangolo specificato da una coppia di coordinate, una larghezza e un'altezza.

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)

Parametri

pen
Pen

Oggetto Pen che determina il colore, la larghezza e lo stile del rettangolo.

x
Single

Coordinata X dell'angolo superiore sinistro del rettangolo da disegnare.

y
Single

Coordinata Y dell'angolo superiore sinistro del rettangolo da disegnare.

width
Single

Larghezza del rettangolo da disegnare.

height
Single

Altezza del rettangolo da disegnare.

Eccezioni

pen è null.

Esempio

L'esempio di codice seguente è progettato per l'uso con Windows Forms e richiede PaintEventArgse, che è un parametro del Paint gestore eventi. Il codice esegue le azioni seguenti:

  • Crea una penna nera.

  • Crea la posizione e le dimensioni di un rettangolo.

  • Disegna il rettangolo sullo schermo.

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

Commenti

Per informazioni su come disegnare un RectangleFoggetto , vedere DrawRectangles(Pen, RectangleF[]).

Si applica a

DrawRectangle(Pen, RectangleF)

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

Disegna la struttura del rettangolo specificato.

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)

Parametri

pen
Pen

Penna che determina il colore, la larghezza e lo stile del rettangolo.

rect
RectangleF

Rettangolo da disegnare.

Si applica a

DrawRectangle(Pen, Rectangle)

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

Disegna un rettangolo specificato da una struttura 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)

Parametri

pen
Pen

Oggetto Pen che determina il colore, la larghezza e lo stile del rettangolo.

rect
Rectangle

Struttura Rectangle che rappresenta il rettangolo da disegnare.

Eccezioni

pen è null.

Esempio

L'esempio di codice seguente è progettato per l'uso con Windows Forms e richiede PaintEventArgse, che è un parametro del Paint gestore eventi. Il codice esegue le azioni seguenti:

  • Crea una penna nera.

  • Crea un rettangolo.

  • Disegna il rettangolo sullo schermo.

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

Commenti

Per informazioni su come disegnare un RectangleFoggetto , vedere DrawRectangles(Pen, RectangleF[]).

Si applica a