Graphics.DrawRectangle Metoda

Definicja

Rysuje prostokąt określony przez parę współrzędnych, szerokość i wysokość.

Przeciążenia

Nazwa Opis
DrawRectangle(Pen, Rectangle)

Rysuje prostokąt określony przez Rectangle strukturę.

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

Rysuje prostokąt określony przez parę współrzędnych, szerokość i wysokość.

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

Rysuje prostokąt określony przez parę współrzędnych, szerokość i wysokość.

DrawRectangle(Pen, Rectangle)

Rysuje prostokąt określony przez Rectangle strukturę.

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

Element Pen określający kolor, szerokość i styl prostokąta.

rect
Rectangle

Struktura Rectangle reprezentująca prostokąt do rysowania.

Wyjątki

Parametr pen ma wartość null.

Przykłady

Poniższy przykład kodu jest przeznaczony do użycia z Windows Forms i wymaga PaintEventArgse, który jest parametrem programu obsługi zdarzeń Paint. Kod wykonuje następujące akcje:

  • Tworzy długopis.

  • Tworzy prostokąt.

  • Rysuje prostokąt na ekranie.

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

Uwagi

Aby uzyskać informacje na temat rysowania elementu RectangleF, zobacz DrawRectangles(Pen, RectangleF[]).

Dotyczy

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

Rysuje prostokąt określony przez parę współrzędnych, szerokość i wysokość.

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 określa kolor, szerokość i styl prostokąta.

x
Int32

Współrzędna x lewego górnego rogu prostokąta do rysowania.

y
Int32

Współrzędna y lewego górnego rogu prostokąta do rysowania.

width
Int32

Szerokość prostokąta do rysowania.

height
Int32

Wysokość prostokąta do rysowania.

Wyjątki

Parametr pen ma wartość null.

Przykłady

Poniższy przykład kodu jest przeznaczony do użycia z Windows Forms i wymaga PaintEventArgse, który jest parametrem programu obsługi zdarzeń Paint. Kod wykonuje następujące akcje:

  • Tworzy długopis.

  • Tworzy położenie i rozmiar prostokąta.

  • Rysuje prostokąt na ekranie.

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

Uwagi

Aby uzyskać informacje na temat rysowania elementu RectangleF, zobacz DrawRectangles(Pen, RectangleF[]).

Dotyczy

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

Rysuje prostokąt określony przez parę współrzędnych, szerokość i wysokość.

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

Element Pen określający kolor, szerokość i styl prostokąta.

x
Single

Współrzędna x lewego górnego rogu prostokąta do rysowania.

y
Single

Współrzędna y lewego górnego rogu prostokąta do rysowania.

width
Single

Szerokość prostokąta do rysowania.

height
Single

Wysokość prostokąta do rysowania.

Wyjątki

Parametr pen ma wartość null.

Przykłady

Poniższy przykład kodu jest przeznaczony do użycia z Windows Forms i wymaga PaintEventArgse, który jest parametrem programu obsługi zdarzeń Paint. Kod wykonuje następujące akcje:

  • Tworzy długopis.

  • Tworzy położenie i rozmiar prostokąta.

  • Rysuje prostokąt na ekranie.

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

Uwagi

Aby uzyskać informacje na temat rysowania elementu RectangleF, zobacz DrawRectangles(Pen, RectangleF[]).

Dotyczy