Rect.Contains 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
指示矩形中是否包含指定的点或矩形。
重载
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
要检查的点。
返回
如果矩形中包含指定点,则为 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
要检查的矩形。
返回
如果 rect
完全包含在矩形中,则为 true
;否则为 false
。
示例
以下示例演示如何使用 Contains(Rect) 方法确定一个矩形是否包含另一个矩形。
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 坐标。
返回
如果(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;
}