Export (0) Print
Expand All

RectangleF.Inflate Method (SizeF)

Enlarges this RectangleF by the specified amount.

Namespace:  System.Drawing
Assembly:  System.Drawing (in System.Drawing.dll)

public void Inflate(
	SizeF size


Type: System.Drawing.SizeF

The amount to inflate this rectangle.

This method enlarges this rectangle, not a copy of it. The rectangle is enlarged in both directions along an axis. For example, if a 50 by 50 rectangle is inflated by 50 in the x-axis, the resultant rectangle will be 150 units long (the original 50, the 50 in the minus direction, and the 50 in the plus direction) maintaining the rectangle's geometric center.

This example is designed for use with Windows Forms, and it requires PaintEventArgs e, an OnPaint event object. The code creates a RectangleF and draws it to the screen in black. Notice that it has to be converted to a Rectangle for drawing purposes. Then the code enlarges the RectangleF, again converts it to a Rectangle, and draws it to the screen in red. Notice that the original (black) rectangle is expanded in both directions along the x-axis by 100 points.

public void RectangleFInflateExample(PaintEventArgs e)

    // Create a RectangleF structure.
    RectangleF myRectF = new RectangleF(100, 20, 100, 100);

    // Draw myRect to the screen.
    Rectangle myRect = Rectangle.Truncate(myRectF);
    e.Graphics.DrawRectangle(Pens.Black, myRect);

    // Create a Size structure.
    SizeF inflateSize = new SizeF(100, 0);

    // Inflate myRect.

    // Draw the inflated rectangle to the screen.
    myRect = Rectangle.Truncate(myRectF);
    e.Graphics.DrawRectangle(Pens.Red, myRect);

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

© 2014 Microsoft