Printer Friendly Version      Send     
Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
Previous Versions
.NET Framework 1.1
.NET Framework
Reference
System.Drawing
Graphics Class
Methods
This page is specific to
Microsoft Visual Studio 2003/.NET Framework 1.1

Other versions are also available for the following:
.NET Framework Class Library
Graphics.DrawRectangle Method

Draws a rectangle specified by a coordinate pair, a width, and a height.

Overload List

Draws a rectangle specified by a Rectangle structure.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Sub DrawRectangle(Pen, Rectangle)
[C#] public void DrawRectangle(Pen, Rectangle);
[C++] public: void DrawRectangle(Pen*, Rectangle);
[JScript] public function DrawRectangle(Pen, Rectangle);

Draws a rectangle specified by a coordinate pair, a width, and a height.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Sub DrawRectangle(Pen, Integer, Integer, Integer, Integer)
[C#] public void DrawRectangle(Pen, int, int, int, int);
[C++] public: void DrawRectangle(Pen*, int, int, int, int);
[JScript] public function DrawRectangle(Pen, int, int, int, int);

Draws a rectangle specified by a coordinate pair, a width, and a height.

[Visual Basic] Overloads Public Sub DrawRectangle(Pen, Single, Single, Single, Single)
[C#] public void DrawRectangle(Pen, float, float, float, float);
[C++] public: void DrawRectangle(Pen*, float, float, float, float);
[JScript] public function DrawRectangle(Pen, float, float, float, float);

Example

[Visual Basic, C#] The following example is designed for use with Windows Forms, and it requires PaintEventArgs e, which is a parameter of the Paint event handler. The code performs the following actions:

  • Creates a black pen.
  • Creates the position and size of a rectangle.
  • Draws the rectangle to the screen.
[Visual Basic, C#] Note   This example shows how to use one of the overloaded versions of DrawRectangle. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Public Sub DrawRectangleFloat(e As PaintEventArgs)
' Create pen.
Dim blackPen As New Pen(Color.Black, 3)
' Create location and size of rectangle.
Dim x As Single = 0F
Dim y As Single = 0F
Dim width As Single = 200F
Dim height As Single = 200F
' Draw rectangle to screen.
e.Graphics.DrawRectangle(blackPen, x, y, width, height)
End Sub
        
[C#] 
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);
}
        

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

Graphics Class | Graphics Members | System.Drawing Namespace

© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker