次の方法で共有


Graphics.DrawRectangle メソッド (Pen, Int32, Int32, Int32, Int32)

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

Overloads Public Sub DrawRectangle( _
   ByVal pen As Pen, _   ByVal x As Integer, _   ByVal y As Integer, _   ByVal width As Integer, _   ByVal height As Integer _)
[C#]
public void DrawRectangle(Penpen,intx,inty,intwidth,intheight);
[C++]
public: void DrawRectangle(Pen* pen,intx,inty,intwidth,intheight);
[JScript]
public function DrawRectangle(
   pen : Pen,x : int,y : int,width : int,height : int);

パラメータ

  • pen
    四角形の色、幅、およびスタイルを決定する Pen オブジェクト。
  • x
    描画する四角形の左上隅の x 座標。
  • y
    描画する四角形の左上隅の y 座標。
  • width
    描画する四角形の幅。
  • height
    描画する四角形の高さ。

戻り値

このメソッドは値を返しません。

使用例

[Visual Basic, C#] 次の例は、Windows フォームでの使用を意図してデザインされており、 Paint イベント ハンドラのパラメータである PaintEventArgs e が必要です。このコードは次のアクションを実行します。

  • 黒いペンを作成します。
  • 四角形の位置とサイズを作成します。
  • 画面に四角形を描画します。
 
Public Sub DrawRectangleInt(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
        
[C#] 
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);
}
        

[C++, JScript] C++ および JScript のサンプルはありません。Visual Basic および C# のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET

参照

Graphics クラス | Graphics メンバ | System.Drawing 名前空間 | Graphics.DrawRectangle オーバーロードの一覧