次の方法で共有


Graphics.DrawRectangle メソッド

定義

座標ペア、幅、および高さで指定された四角形を描画します。

オーバーロード

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

座標ペア、幅、および高さで指定された四角形を描画します。

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

座標ペア、幅、および高さで指定された四角形を描画します。

DrawRectangle(Pen, RectangleF)

指定した四角形のアウトラインを描画します。

DrawRectangle(Pen, Rectangle)

Rectangle 構造体で指定された四角形を描画します。

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

ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs

座標ペア、幅、および高さで指定された四角形を描画します。

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)

パラメーター

pen
Pen

四角形の色、幅、およびスタイルを決定する Pen

x
Int32

描画する四角形の左上隅の x 座標。

y
Int32

描画する四角形の左上隅の y 座標。

width
Int32

描画する四角形の幅。

height
Int32

描画する四角形の高さ。

例外

pennullです。

次のコード例は、Windows フォームで使用するように設計されており、イベント ハンドラーのPaintパラメーターである が必要PaintEventArgseです。 コードは、次のアクションを実行します。

  • 黒いペンを作成します。

  • 四角形の位置とサイズを作成します。

  • 四角形を画面に描画します。

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

注釈

を描画 RectangleFする方法については、「」を参照してください DrawRectangles(Pen, RectangleF[])

適用対象

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

ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs

座標ペア、幅、および高さで指定された四角形を描画します。

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)

パラメーター

pen
Pen

四角形の色、幅、およびスタイルを決定する Pen

x
Single

描画する四角形の左上隅の x 座標。

y
Single

描画する四角形の左上隅の y 座標。

width
Single

描画する四角形の幅。

height
Single

描画する四角形の高さ。

例外

pennullです。

次のコード例は、Windows フォームで使用するように設計されており、イベント ハンドラーのPaintパラメーターである が必要PaintEventArgseです。 コードは、次のアクションを実行します。

  • 黒いペンを作成します。

  • 四角形の位置とサイズを作成します。

  • 四角形を画面に描画します。

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

注釈

を描画 RectangleFする方法については、「」を参照してください DrawRectangles(Pen, RectangleF[])

適用対象

DrawRectangle(Pen, RectangleF)

ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs

指定した四角形のアウトラインを描画します。

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)

パラメーター

pen
Pen

四角形の色、幅、スタイルを決定するペン。

rect
RectangleF

描画する四角形。

適用対象

DrawRectangle(Pen, Rectangle)

ソース:
Graphics.cs
ソース:
Graphics.cs
ソース:
Graphics.cs

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)

パラメーター

pen
Pen

四角形の色、幅、およびスタイルを決定する Pen

rect
Rectangle

描画する四角形を表す Rectangle 構造体。

例外

pennullです。

次のコード例は、Windows フォームで使用するように設計されており、イベント ハンドラーのPaintパラメーターである が必要PaintEventArgseです。 コードは、次のアクションを実行します。

  • 黒いペンを作成します。

  • 四角形を作成します。

  • 四角形を画面に描画します。

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

注釈

を描画 RectangleFする方法については、「」を参照してください DrawRectangles(Pen, RectangleF[])

適用対象