Rect.Contains Metoda

Definice

Určuje, zda obdélník obsahuje zadaný bod nebo obdélník.

Přetížení

Contains(Point)

Určuje, zda obdélník obsahuje zadaný bod.

Contains(Rect)

Určuje, zda obdélník obsahuje zadaný obdélník.

Contains(Double, Double)

Určuje, zda obdélník obsahuje zadanou souřadnici x a souřadnici y.

Contains(Point)

Určuje, zda obdélník obsahuje zadaný bod.

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

Parametry

point
Point

Bod, který chcete zkontrolovat.

Návraty

Boolean

truepokud obdélník obsahuje zadaný bod; v opačném případě . false

Příklady

Následující příklad ukazuje, jak použít metodu Contains(Point) k určení, zda obdélník obsahuje zadaný 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;
}

Platí pro

Contains(Rect)

Určuje, zda obdélník obsahuje zadaný obdélník.

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

Parametry

rect
Rect

Obdélník, který chcete zkontrolovat.

Návraty

Boolean

true je-li rect zcela obsažena obdélníkem; jinak, false.

Příklady

Následující příklad ukazuje, jak použít metodu Contains(Rect) k určení, jestli jeden obdélník je obsažen jiným obdélníkem.

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

Platí pro

Contains(Double, Double)

Určuje, zda obdélník obsahuje zadanou souřadnici x a souřadnici 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

Parametry

x
Double

Souřadnice x bodu, který chcete zkontrolovat.

y
Double

Souřadnice bodu, který chcete zkontrolovat.

Návraty

Boolean

true pokud (x, y) je obsažen obdélník; jinak, false.

Příklady

Následující příklad ukazuje, jak použít metodu Contains(Double, Double) k určení, zda obdélník obsahuje bod určený daný souřadnicí x a souřadnicí 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;
}

Platí pro