Graphics.FillRectangles Method

Definition

Fills the interiors of a series of rectangles specified by Rectangle structures.

Overloads

FillRectangles(Brush, ReadOnlySpan<RectangleF>)

Fills the interiors of a series of rectangles specified by RectangleF structures.

FillRectangles(Brush, ReadOnlySpan<Rectangle>)

Fills the interiors of a series of rectangles specified by RectangleF structures.

FillRectangles(Brush, RectangleF[])

Fills the interiors of a series of rectangles specified by RectangleF structures.

FillRectangles(Brush, Rectangle[])

Fills the interiors of a series of rectangles specified by Rectangle structures.

FillRectangles(Brush, ReadOnlySpan<RectangleF>)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

Fills the interiors of a series of rectangles specified by RectangleF structures.

C#
public void FillRectangles(System.Drawing.Brush brush, scoped ReadOnlySpan<System.Drawing.RectangleF> rects);

Parameters

brush
Brush

Brush that determines the characteristics of the fill.

rects
ReadOnlySpan<RectangleF>

Array of RectangleF structures that represent the rectangles to fill.

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 9 (package-provided), 10 (package-provided)
Windows Desktop 9, 10

FillRectangles(Brush, ReadOnlySpan<Rectangle>)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

Fills the interiors of a series of rectangles specified by RectangleF structures.

C#
public void FillRectangles(System.Drawing.Brush brush, scoped ReadOnlySpan<System.Drawing.Rectangle> rects);

Parameters

brush
Brush

Brush that determines the characteristics of the fill.

rects
ReadOnlySpan<Rectangle>

Array of RectangleF structures that represent the rectangles to fill.

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 9 (package-provided), 10 (package-provided)
Windows Desktop 9, 10

FillRectangles(Brush, RectangleF[])

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

Fills the interiors of a series of rectangles specified by RectangleF structures.

C#
public void FillRectangles(System.Drawing.Brush brush, params System.Drawing.RectangleF[] rects);
C#
public void FillRectangles(System.Drawing.Brush brush, System.Drawing.RectangleF[] rects);

Parameters

brush
Brush

Brush that determines the characteristics of the fill.

rects
RectangleF[]

Array of RectangleF structures that represent the rectangles to fill.

Exceptions

brush is null.

-or-

rects is null.

rects is a zero-length array.

Examples

The following code 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 action:

  • Creates a solid blue brush.
  • Creates an array of three rectangles.
  • Fills the three rectangular areas on the screen.
C#
private void FillRectanglesRectangleF(PaintEventArgs e)
{

    // Create solid brush.
    SolidBrush blueBrush = new SolidBrush(Color.Blue);

    // 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) };

    // Fill rectangles to screen.
    e.Graphics.FillRectangles(blueBrush, rects);
}

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

FillRectangles(Brush, Rectangle[])

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

Fills the interiors of a series of rectangles specified by Rectangle structures.

C#
public void FillRectangles(System.Drawing.Brush brush, params System.Drawing.Rectangle[] rects);
C#
public void FillRectangles(System.Drawing.Brush brush, System.Drawing.Rectangle[] rects);

Parameters

brush
Brush

Brush that determines the characteristics of the fill.

rects
Rectangle[]

Array of Rectangle structures that represent the rectangles to fill.

Exceptions

brush is null.

-or-

rects is null.

rects is a zero-length array.

Examples

The following code 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 action:

  • Creates a solid blue brush.

  • Creates an array of three rectangles.

  • Fills the three rectangular areas on the screen.

C#
private void FillRectanglesRectangle(PaintEventArgs e)
{

    // Create solid brush.
    SolidBrush blueBrush = new SolidBrush(Color.Blue);

    // Create array of rectangles.
    Rectangle[] rects = { new Rectangle(0, 0, 100, 200), new Rectangle(100, 200, 250, 50), new Rectangle(300, 0, 50, 100) };

    // Fill rectangles to screen.
    e.Graphics.FillRectangles(blueBrush, rects);
}

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10