Rect.Inflate 方法

定义

创建一个矩形,该矩形是通过将一个矩形放大或缩小指定量而得到的。

重载

Inflate(Size)

使用指定的 Size 向所有方向放大矩形。

Inflate(Double, Double)

使用指定的宽度和高度量向所有方向放大或缩小矩形。

Inflate(Rect, Size)

返回矩形,该矩形是通过将指定矩形向所有方向放大指定 Size 而得到的。

Inflate(Rect, Double, Double)

创建一个矩形,该矩形是通过将指定矩形向所有方向放大或缩小指定宽度和高度而得到的。

Inflate(Size)

使用指定的 Size 向所有方向放大矩形。

public:
 void Inflate(System::Windows::Size size);
public void Inflate (System.Windows.Size size);
member this.Inflate : System.Windows.Size -> unit
Public Sub Inflate (size As Size)

参数

size
Size

指定矩形的放大量。 Size 结构的 Width 属性指定矩形的 LeftRight 属性的增量。 Size 结构的 Height 属性指定矩形的 TopBottom 属性的增量。

例外

Empty 矩形调用此方法。

示例

以下示例演示如何使用 Inflate(Size) 该方法增加矩形的大小。

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

注解

Width生成的矩形由指定Size结构的两倍Width增加,因为矩形的左右两侧都膨胀。 同样,Height生成的矩形将增加指定Size结构的两倍Height

另请参阅

适用于

Inflate(Double, Double)

使用指定的宽度和高度量向所有方向放大或缩小矩形。

public:
 void Inflate(double width, double height);
public void Inflate (double width, double height);
member this.Inflate : double * double -> unit
Public Sub Inflate (width As Double, height As Double)

参数

width
Double

矩形左边和右边的放大或缩小量。

height
Double

矩形上边和下边的放大或缩小量。

例外

Empty 矩形调用此方法。

示例

下面的示例演示如何使用 Inflate(Double, Double) 该方法更改矩形的大小。

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

注解

Width生成的矩形增加或减少两倍指定的宽度偏移量,因为它同时应用于矩形的左侧和右侧。 同样, Height 生成的矩形将增加或减少指定高度的两倍。

如果指定的宽度或高度比矩形的当前 Width Height 宽度或高度缩小矩形,或者为矩形提供负区域,则矩形将成为 Empty 矩形。

另请参阅

适用于

Inflate(Rect, Size)

返回矩形,该矩形是通过将指定矩形向所有方向放大指定 Size 而得到的。

public:
 static System::Windows::Rect Inflate(System::Windows::Rect rect, System::Windows::Size size);
public static System.Windows.Rect Inflate (System.Windows.Rect rect, System.Windows.Size size);
static member Inflate : System.Windows.Rect * System.Windows.Size -> System.Windows.Rect
Public Shared Function Inflate (rect As Rect, size As Size) As Rect

参数

rect
Rect

要修改的 Rect 结构。

size
Size

指定矩形的放大量。 Size 结构的 Width 属性指定矩形的 LeftRight 属性的增量。 Size 结构的 Height 属性指定矩形的 TopBottom 属性的增量。

返回

Rect

所得矩形。

例外

rectEmpty 矩形。

示例

下面的示例演示如何使用 Inflate(Rect, Size) 该方法更改矩形的大小。

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

注解

Width生成的矩形由指定Size结构的两倍Width增加,因为矩形的左右两侧都膨胀。 同样,Height生成的矩形将增加指定Size结构的两倍Height

另请参阅

适用于

Inflate(Rect, Double, Double)

创建一个矩形,该矩形是通过将指定矩形向所有方向放大或缩小指定宽度和高度而得到的。

public:
 static System::Windows::Rect Inflate(System::Windows::Rect rect, double width, double height);
public static System.Windows.Rect Inflate (System.Windows.Rect rect, double width, double height);
static member Inflate : System.Windows.Rect * double * double -> System.Windows.Rect
Public Shared Function Inflate (rect As Rect, width As Double, height As Double) As Rect

参数

rect
Rect

要修改的 Rect 结构。

width
Double

矩形左边和右边的放大或缩小量。

height
Double

矩形上边和下边的放大或缩小量。

返回

Rect

所得矩形。

例外

rectEmpty 矩形。

示例

下面的示例演示如何使用 Inflate(Rect, Double, Double) 该方法更改矩形的大小。

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

注解

Width生成的矩形增加或减少两倍指定的宽度偏移量,因为它同时应用于矩形的左侧和右侧。 同样, Height 生成的矩形将增加或减少指定高度的两倍。

如果指定的宽度或高度修饰符将矩形缩小为当前 Width Height 或为矩形提供负区域,则此方法返回 Rect.Empty

另请参阅

适用于