Export (0) Print
Expand All

Rectangle.Inflate Method (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.

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

public static Rectangle Inflate(
	Rectangle rect,
	int x,
	int y
)

Parameters

rect
Type: System.Drawing.Rectangle

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

x
Type: System.Int32

The amount to inflate this Rectangle horizontally.

y
Type: System.Int32

The amount to inflate this Rectangle vertically.

Return Value

Type: System.Drawing.Rectangle
The enlarged Rectangle.

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.

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.

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

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft