Export (0) Print
Expand All

Graphics.DrawRectangles Method

Draws a series of rectangles specified by Rectangle structures.

Overload List

Draws a series of rectangles specified by Rectangle structures.

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

Draws a series of rectangles specified by RectangleF structures.

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

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 an array of three rectangles.
  • Draws the rectangles to the screen.
[Visual Basic, C#] Note   This example shows how to use one of the overloaded versions of DrawRectangles. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Public Sub DrawRectanglesRectangleF(e As PaintEventArgs)
' Create pen.
Dim blackPen As New Pen(Color.Black, 3)
' Create array of rectangles.
Dim rects As RectangleF() =  {New RectangleF(0F, 0F, 100F, 200F), _
New RectangleF(100F, 200F, 250F, 50F), _
New RectangleF(300F, 0F, 50F, 100F)}
' Draw rectangles to screen.
e.Graphics.DrawRectangles(blackPen, rects)
End Sub
        
[C#] 
public void DrawRectanglesRectangleF(PaintEventArgs e)
{
// Create pen.
Pen blackPen = new Pen(Color.Black, 3);
// Create array of rectangles.
RectangleF[] rects =
{
new RectangleF(  0.0F,   0.0F, 100.0F, 200.0F),
new RectangleF(100.0F, 200.0F, 250.0F,  50.0F),
new RectangleF(300.0F,   0.0F,  50.0F, 100.0F)
};
// Draw rectangles to screen.
e.Graphics.DrawRectangles(blackPen, rects);
}
        

[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

Show:
© 2014 Microsoft