Rect.Contains メソッド

定義

指定した点または四角形が、四角形に含まれているかどうかを示します。

オーバーロード

Contains(Point)

四角形に指定した点が含まれているかどうかを示します。

Contains(Rect)

指定した四角形が、四角形に含まれているかどうかを示します。

Contains(Double, Double)

指定した x 座標と y 座標が、四角形に含まれているかどうかを示します。

Contains(Point)

四角形に指定した点が含まれているかどうかを示します。

public:
 bool Contains(System::Windows::Point point);
public bool Contains (System.Windows.Point point);
member this.Contains : System.Windows.Point -> bool
Public Function Contains (point As Point) As Boolean

パラメーター

point
Point

確認対象の点。

戻り値

Boolean

指定した点が、四角形に含まれている場合は true。それ以外の場合は false

次の例は、このメソッドを使用 Contains(Point) して、指定した Point四角形が含まれているかどうかを判断する方法を示しています。

private bool rectContainsExample1()
{
    // 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);

    // Using the Contains method, see if the rectangle contains the specified
    // point. doesContain is true because the point is inside of myRectangle.
    bool doesContain = myRectangle.Contains(new Point(13, 30));

    return doesContain;
}

適用対象

Contains(Rect)

指定した四角形が、四角形に含まれているかどうかを示します。

public:
 bool Contains(System::Windows::Rect rect);
public bool Contains (System.Windows.Rect rect);
member this.Contains : System.Windows.Rect -> bool
Public Function Contains (rect As Rect) As Boolean

パラメーター

rect
Rect

確認対象の四角形。

戻り値

Boolean

rect 全体が、四角形に含まれている場合は true。それ以外の場合は false

次の例は、メソッドを Contains(Rect) 使用して、1 つの四角形が別の四角形に含まれているかどうかを判断する方法を示しています。

private bool rectContainsExample2()
{
    // 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.
    Rect myRectangle2 = new Rect();
    myRectangle2.Location = new Point(12, 12);
    myRectangle2.Size = new Size(10, 60);

    // Using the Contains method, see if the second rectangle is 
    // contained within the first rectangle. doesContain is false
    // because only part of myRectangle2 is contained in myRectangle1 
    // (myRectangle2 is too wide).
    bool doesContain = myRectangle1.Contains(myRectangle2);

    return doesContain;
}

適用対象

Contains(Double, Double)

指定した x 座標と y 座標が、四角形に含まれているかどうかを示します。

public:
 bool Contains(double x, double y);
public bool Contains (double x, double y);
member this.Contains : double * double -> bool
Public Function Contains (x As Double, y As Double) As Boolean

パラメーター

x
Double

確認対象の点の x 座標。

y
Double

確認対象の点の y 座標。

戻り値

Boolean

(x,y) の座標が、四角形に含まれている場合は true。それ以外の場合は false

次の例は、このメソッドを Contains(Double, Double) 使用して、指定された x 座標と y 座標で指定された点が四角形に含まれているかどうかを判断する方法を示しています。

private bool rectContainsExample3()
{
    // 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);

    // Using the Contains method, see if the rectangle contains the specified
    // point specified by the given X and Y coordinates. doesContain is false 
    // because the X and Y coordinates specify a point outside of myRectangle.
    bool doesContain = myRectangle.Contains(4, 13);

    return doesContain;
}

適用対象