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
Available since 1.1
Return to top