RectangleF.Inflate Method

Definition

Enlarges this RectangleF by the specified amount.

Overloads

Inflate(SizeF)

Enlarges this RectangleF by the specified amount.

Inflate(Single, Single)

Enlarges this RectangleF structure by the specified amount.

Inflate(RectangleF, Single, Single)

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

Inflate(SizeF)

Source:
RectangleF.cs
Source:
RectangleF.cs
Source:
RectangleF.cs

Enlarges this RectangleF by the specified amount.

public void Inflate (System.Drawing.SizeF size);

Parameters

size
SizeF

The amount to inflate this rectangle.

Examples

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.
    myRectF.Inflate(inflateSize);
             
    // Draw the inflated rectangle to the screen.
    myRect = Rectangle.Truncate(myRectF);
    e.Graphics.DrawRectangle(Pens.Red, myRect);
}

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

See also

Applies to

.NET 9 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
.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(Single, Single)

Source:
RectangleF.cs
Source:
RectangleF.cs
Source:
RectangleF.cs

Enlarges this RectangleF structure by the specified amount.

public void Inflate (float x, float y);

Parameters

x
Single

The amount to inflate this RectangleF structure horizontally.

y
Single

The amount to inflate this RectangleF structure vertically.

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

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

Applies to

.NET 9 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
.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(RectangleF, Single, Single)

Source:
RectangleF.cs
Source:
RectangleF.cs
Source:
RectangleF.cs

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

public static System.Drawing.RectangleF Inflate (System.Drawing.RectangleF rect, float x, float y);

Parameters

rect
RectangleF

The RectangleF to be copied. This rectangle is not modified.

x
Single

The amount to enlarge the copy of the rectangle horizontally.

y
Single

The amount to enlarge the copy of the rectangle vertically.

Returns

The enlarged RectangleF.

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

Applies to

.NET 9 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
.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