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所產生矩形的 增加兩倍 WidthSize 因為矩形的左邊和右邊都會擴大。 同樣地,產生的矩形會 Height 增加兩次 Height 指定的 Size 結構。

另請參閱

適用於

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 增加或減少兩次指定的高度。

如果指定的寬度或高度將矩形縮小超過目前 WidthHeight - 為矩形提供負區域 , 矩形就會 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

產生的矩形。

例外狀況

rect 是一種 Empty 矩形。

範例

下列範例示範如何使用 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所產生矩形的 增加兩倍 WidthSize 因為矩形的左邊和右邊都會擴大。 同樣地,產生的矩形會 Height 增加兩次 Height 指定的 Size 結構。

另請參閱

適用於

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

產生的矩形。

例外狀況

rect 是一種 Empty 矩形。

範例

下列範例示範如何使用 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 增加或減少兩次指定的高度。

如果指定的寬度或高度修飾詞將矩形壓縮為目前的 WidthHeight - 為矩形提供負區域 , 這個方法會傳 Rect.Empty 回 。

另請參閱

適用於