Rect.Inflate Method

Definition

Creates a rectangle that results from expanding or shrinking a rectangle by the specified amount.

Overloads

Inflate(Size)

Expands the rectangle by using the specified Size, in all directions.

Inflate(Double, Double)

Expands or shrinks the rectangle by using the specified width and height amounts, in all directions.

Inflate(Rect, Size)

Returns the rectangle that results from expanding the specified rectangle by the specified Size, in all directions.

Inflate(Rect, Double, Double)

Creates a rectangle that results from expanding or shrinking the specified rectangle by the specified width and height amounts, in all directions.

Inflate(Size)

Expands the rectangle by using the specified Size, in all directions.

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

Parameters

size
Size

Specifies the amount to expand the rectangle. The Size structure's Width property specifies the amount to increase the rectangle's Left and Right properties. The Size structure's Height property specifies the amount to increase the rectangle's Top and Bottom properties.

Exceptions

This method is called on the Empty rectangle.

Examples

The following example shows how to use the Inflate(Size) method to increase the size of a rectangle.

C#
private Size inflateExample1()
{
    // Initialize new rectangle.
    Rect myRectangle = new Rect();

    // The Location property specifies the coordinates of the upper left-hand 
    // corner of the rectangle. 
    myRectangle.Location = new Point(10, 5);

    // Set the Size property of the rectangle with a width of 200
    // and a height of 50.
    myRectangle.Size = new Size(200, 50);

    // Use the Inflate method to expand the rectangle by the specified Size in all
    // directions. The new size is 240,110. Note: Width of the resulting rectangle  
    // is increased by twice the Width of the specified Size structure because  
    // both the left and right sides of the rectangle are inflated. Likewise, the 
    // Height of the resulting rectangle is increased by twice the Height of the 
    // specified Size structure.
    myRectangle.Inflate(new Size(20,30));

    return myRectangle.Size;
}

Remarks

The Width of the resulting rectangle is increased by twice the Width of the specified Size structure, because both the left and right sides of the rectangle are inflated. Likewise, the Height of the resulting rectangle is increased by twice the Height of the specified Size structure.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 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
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Inflate(Double, Double)

Expands or shrinks the rectangle by using the specified width and height amounts, in all directions.

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

Parameters

width
Double

The amount by which to expand or shrink the left and right sides of the rectangle.

height
Double

The amount by which to expand or shrink the top and bottom sides of the rectangle.

Exceptions

This method is called on the Empty rectangle.

Examples

The following example shows how to use the Inflate(Double, Double) method to change the size of a rectangle.

C#
private Size inflateExample2()
{
    // Initialize new rectangle.
    Rect myRectangle = new Rect();

    // The Location property specifies the coordinates of the upper left-hand 
    // corner of the rectangle. 
    myRectangle.Location = new Point(10, 5);

    // Set the Size property of the rectangle with a width of 200
    // and a height of 50.
    myRectangle.Size = new Size(200,50);

    // Use the Inflate method to expand or shrink the rectangle by the specified 
    // width and height amounts. The new size is 160,150 (width shrunk by 40 and  
    // height increased by 100). Note: Width of the resulting rectangle is increased 
    // or shrunk by twice the specified width, because both the left and right sides  
    // of the rectangle are inflated or shrunk. Likewise, the height of the resulting 
    // rectangle is increased or shrunk by twice the specified height.
    myRectangle.Inflate(-20,50);

    return myRectangle.Size;
}

Remarks

The Width of the resulting rectangle is increased or decreased by twice the specified width offset, because it is applied to both the left and right sides of the rectangle. Likewise, the Height of the resulting rectangle is increased or decreased by twice the specified height.

If the specified width or height shrink the rectangle by more than its current Width or Height - giving the rectangle a negative area - the rectangle becomes the Empty rectangle.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 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
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Inflate(Rect, Size)

Returns the rectangle that results from expanding the specified rectangle by the specified Size, in all directions.

C#
public static System.Windows.Rect Inflate(System.Windows.Rect rect, System.Windows.Size size);

Parameters

rect
Rect

The Rect structure to modify.

size
Size

Specifies the amount to expand the rectangle. The Size structure's Width property specifies the amount to increase the rectangle's Left and Right properties. The Size structure's Height property specifies the amount to increase the rectangle's Top and Bottom properties.

Returns

The resulting rectangle.

Exceptions

rect is an Empty rectangle.

Examples

The following example shows how to use the Inflate(Rect, Size) method to change the size of a rectangle.

C#
private Size inflateExample3()
{
    // Initialize new rectangle.
    Rect myRectangle = new Rect();

    // The Location property specifies the coordinates of the upper left-hand 
    // corner of the rectangle. 
    myRectangle.Location = new Point(10, 5);

    // Set the Size property of the rectangle with a width of 200
    // and a height of 50.
    myRectangle.Size = new Size(200, 50);

    // Use the static Inflate method to return an expanded version of myRectangle1.   
    // The size of myRectangle2 is 240,110. Note: Width of the resulting rectangle is increased 
    // by twice the Width of the specified Size structure, because both the left and right 
    // sides of the rectangle are inflated. Likewise, the Height of the resulting 
    // rectangle is increased by twice the Height of the specified Size structure.
    Rect myRectangle2 = Rect.Inflate(myRectangle, new Size(20, 30));

    return myRectangle2.Size;
}

Remarks

The Width of the resulting rectangle is increased by twice the Width of the specified Size structure, because both the left and right sides of the rectangle are inflated. Likewise, the Height of the resulting rectangle is increased by twice the Height of the specified Size structure.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 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
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Inflate(Rect, Double, Double)

Creates a rectangle that results from expanding or shrinking the specified rectangle by the specified width and height amounts, in all directions.

C#
public static System.Windows.Rect Inflate(System.Windows.Rect rect, double width, double height);

Parameters

rect
Rect

The Rect structure to modify.

width
Double

The amount by which to expand or shrink the left and right sides of the rectangle.

height
Double

The amount by which to expand or shrink the top and bottom sides of the rectangle.

Returns

The resulting rectangle.

Exceptions

rect is an Empty rectangle.

Examples

The following example shows how to use the Inflate(Rect, Double, Double) method to change the size of a rectangle.

C#
private Size inflateExample4()
{
    // Initialize new rectangle.
    Rect myRectangle = new Rect();

    // The Location property specifies the coordinates of the upper left-hand 
    // corner of the rectangle. 
    myRectangle.Location = new Point(10, 5);

    // Set the Size property of the rectangle with a width of 200
    // and a height of 50.
    myRectangle.Size = new Size(200, 50);

    // Use the static Inflate method to return a version of myRectangle with a shrunk
    // width and expanded height. The size of myRectangle2 is 160,150. Note: Width of the resulting 
    // rectangle is increased or shrunk by twice the specified width, because both the
    // left and right sides of the rectangle are inflated or shrunk. Likewise, the height 
    // of the resulting rectangle is increased or shrunk by twice the specified height.
    Rect myRectangle2 = Rect.Inflate(myRectangle, -20, 50);

    return myRectangle2.Size;
}

Remarks

The Width of the resulting rectangle is increased or decreased by twice the specified width offset, because it is applied to both the left and right sides of the rectangle. Likewise, the Height of the resulting rectangle is increased or decreased by twice the specified height.

If the specified width or height modifiers shrink the rectangle by more than its current Width or Height - giving the rectangle a negative area - this method returns Rect.Empty.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 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
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10