Rectangle.Inflate Method

Definition

Enlarges a Rectangle structure by the specified amount.

Overloads

Inflate(Size)

Enlarges this Rectangle by the specified amount.

Inflate(Int32, Int32)

Enlarges this Rectangle by the specified amount.

Inflate(Rectangle, Int32, Int32)

Creates and returns an enlarged copy of the specified Rectangle structure. The copy is enlarged by the specified amount. The original Rectangle structure remains unmodified.

Inflate(Size)

Source:
Rectangle.cs
Source:
Rectangle.cs
Source:
Rectangle.cs

Enlarges this Rectangle by the specified amount.

C#
public void Inflate(System.Drawing.Size size);

Parameters

size
Size

The amount to inflate this rectangle.

Examples

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

C#
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);
}

Remarks

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 enlarged 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.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.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, 2.1

Inflate(Int32, Int32)

Source:
Rectangle.cs
Source:
Rectangle.cs
Source:
Rectangle.cs

Enlarges this Rectangle by the specified amount.

C#
public void Inflate(int width, int height);

Parameters

width
Int32

The amount to inflate this Rectangle horizontally.

height
Int32

The amount to inflate this Rectangle vertically.

Examples

The following example creates a Rectangle structure and enlarges it by 100 units in the x-axis direction:

C#
public void RectangleInflateTest3(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);
             
    // Call Inflate.
    rect.Inflate(50, 50);
             
    // Draw the inflated rectangle to screen.
    e.Graphics.DrawRectangle(Pens.Red, rect);
}

Remarks

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 enlarged 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.

If either x or y is negative, the Rectangle structure is deflated in the corresponding direction.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.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, 2.1

Inflate(Rectangle, Int32, Int32)

Source:
Rectangle.cs
Source:
Rectangle.cs
Source:
Rectangle.cs

Creates and returns an enlarged copy of the specified Rectangle structure. The copy is enlarged by the specified amount. The original Rectangle structure remains unmodified.

C#
public static System.Drawing.Rectangle Inflate(System.Drawing.Rectangle rect, int x, int y);

Parameters

rect
Rectangle

The Rectangle with which to start. This rectangle is not modified.

x
Int32

The amount to inflate this Rectangle horizontally.

y
Int32

The amount to inflate this Rectangle vertically.

Returns

The enlarged Rectangle.

Examples

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 enlarges it by 50 units in both axes. Notice that the resulting rectangle (red) is 150 units in both axes.

C#
public void RectangleInflateTest(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);
             
    // Call Inflate.
    Rectangle rect2 = Rectangle.Inflate(rect, 50, 50);
             
    // Draw the inflated rectangle to screen.
    e.Graphics.DrawRectangle(Pens.Red, rect2);
}

Remarks

This method makes a copy of rect, enlarges the copy, and then returns the enlarged copy. The rectangle is enlarged in both directions along an axis. For example, if a 50 by 50 rectangle is enlarged 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.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.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, 2.1