Export (0) Print
Expand All

Rect.Equals Method (Rect)

Determines whether the specified rectangle is equal to this rectangle.

Namespace: System.Windows
Assembly: WindowsBase (in windowsbase.dll)

public bool Equals (
	Rect value
)
public boolean Equals (
	Rect value
)
public function Equals (
	value : Rect
) : boolean
You cannot use methods in XAML.

Parameters

value

The rectangle to compare.

Return Value

true if both rectangles have the same position, Width, and Height as this rectangle; otherwise, false.

This operation tests for object equality.

In this comparison, NaN is considered equal to itself.

NoteNote:

A rectangle's position and dimensions are described by Double values. Because Double values can lose precision when operated upon, a comparison between two values that are logically equal might fail.

This example shows how to use the Equals method to determine if one rectangle is equal to another.

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;

}

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show:
© 2014 Microsoft