This documentation is archived and is not being maintained.

Rectangle.Inflate Method (Size)

Inflates this Rectangle by the specified amount.

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

public void Inflate(
	Size size
)

Parameters

size
Type: System.Drawing.Size

The amount to inflate this rectangle.

This method inflates this rectangle, not a copy of it. The inflation along an axis is in two directions (minus direction and plus direction). 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.

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 creates a Rectangle and inflates it by 50 units in both axes. The rectangle is drawn to screen before inflation (black) and after inflation (red).

public void RectangleInflateTest2(PaintEventArgs e)
{

    // Create a rectangle.
    Rectangle rect = new Rectangle(100, 100, 50, 50);

    // Draw the uninflated rectangle to screen.
    e.Graphics.DrawRectangle(Pens.Black, rect);

    // Set up the inflate size.
    Size inflateSize = new Size(50, 50);

    // Call Inflate.
    rect.Inflate(inflateSize);

    // Draw the inflated rectangle to screen.
    e.Graphics.DrawRectangle(Pens.Red, rect);
}

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Show: