Rect.Equals 方法

定義

表示兩個矩形是否相等。

多載

Equals(Rect, Rect)

表示指定的矩形是否相等。

Equals(Object)

表示指定的物件是否等於目前矩形。

Equals(Rect)

表示指定的矩形是否等於目前矩形。

Equals(Rect, Rect)

表示指定的矩形是否相等。

public:
 static bool Equals(System::Windows::Rect rect1, System::Windows::Rect rect2);
public static bool Equals (System.Windows.Rect rect1, System.Windows.Rect rect2);
static member Equals : System.Windows.Rect * System.Windows.Rect -> bool
Public Shared Function Equals (rect1 As Rect, rect2 As Rect) As Boolean

參數

rect1
Rect

要比較的第一個矩形。

rect2
Rect

要比較的第二個矩形。

傳回

如果矩形具有相同的 LocationSize 值則為 true,否則為 false

範例

下列範例示範如何使用 Equals(Rect, Rect) 方法來判斷某個矩形是否等於另一個矩形。

private bool rectEqualsExample2()
{
    // Create a rectangle.
    Rect myRectangle1 = new Rect();

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

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

    // Create second rectangle to compare to the first.
    Rect myRectangle2 = new Rect();
    myRectangle2.Location = new Point(10, 5);
    myRectangle2.Size = new Size(200, 50);

    // Using the Equals method, see if the second rectangle is 
    // the same as the first rectangle. doesEqual is true because
    // both rectangles are exactly the same in that they both have the 
    // same location and size.
    bool doesEqual = Rect.Equals(myRectangle1, myRectangle2);

    return doesEqual;
}

備註

這項作業會測試物件是否相等。

在此比較中,會將 的兩個 Double.NaN 實例視為相等。

注意

矩形的位置和維度是由 Double 值所描述。 因為值在操作時可能會失去有效位數,因此 Double 邏輯上相等的兩個值之間的比較可能會失敗。

另請參閱

適用於

Equals(Object)

表示指定的物件是否等於目前矩形。

public:
 override bool Equals(System::Object ^ o);
public override bool Equals (object o);
override this.Equals : obj -> bool
Public Overrides Function Equals (o As Object) As Boolean

參數

o
Object

要與目前矩形相比較的物件。

傳回

如果 oRect 而且具有與目前矩形相同的 LocationSize 值則為 true,否則為 false

範例

下列範例示範如何使用 Equals(Object) 方法來判斷矩形是否等於指定的物件。

private bool rectEqualsExample1()
{
    // Create a rectangle.
    Rect myRectangle1 = new Rect();

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

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

    // Create second rectangle to compare to the first.
    Rect myRectangle2 = new Rect();
    myRectangle2.Location = new Point(10, 5);
    myRectangle2.Size = new Size(200, 50);

    // Using the Equals method, see if the second rectangle is the
    // same as the first rectangle. doesEqual is true because both
    // rectangles are exactly the same with respect to location and size. 
    bool doesEqual = myRectangle1.Equals(myRectangle2);

    return doesEqual;
}

備註

這項作業會測試物件是否相等。

在此比較中,會將 的兩個 Double.NaN 實例視為相等。

注意

矩形的位置和維度是由 Double 值所描述。 因為值在操作時可能會失去有效位數,因此 Double 邏輯上相等的兩個值之間的比較可能會失敗。

另請參閱

適用於

Equals(Rect)

表示指定的矩形是否等於目前矩形。

public:
 bool Equals(System::Windows::Rect value);
public bool Equals (System.Windows.Rect value);
override this.Equals : System.Windows.Rect -> bool
Public Function Equals (value As Rect) As Boolean

參數

value
Rect

要與目前矩形相比較的矩形。

傳回

如果指定的矩形具有與目前矩形相同的 LocationSize 值則為 true,否則為 false

範例

下列範例示範如何使用 Equals(Rect) 方法來判斷矩形是否等於指定的矩形。

private bool rectEqualsExample1()
{
    // Create a rectangle.
    Rect myRectangle1 = new Rect();

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

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

    // Create second rectangle to compare to the first.
    Rect myRectangle2 = new Rect();
    myRectangle2.Location = new Point(10, 5);
    myRectangle2.Size = new Size(200, 50);

    // Using the Equals method, see if the second rectangle is the
    // same as the first rectangle. doesEqual is true because both
    // rectangles are exactly the same with respect to location and size. 
    bool doesEqual = myRectangle1.Equals(myRectangle2);

    return doesEqual;
}

備註

這項作業會測試物件是否相等。

在此比較中,會將 的兩個 Double.NaN 實例視為相等。

注意

矩形的位置和維度是由 Double 值所描述。 因為值在操作時可能會失去有效位數,因此 Double 邏輯上相等的兩個值之間的比較可能會失敗。

另請參閱

適用於