Rectangle.Contains 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
确定指定的点是否包含在此 Rectangle 定义的矩形区域范围内。
重载
Contains(Point) |
确定指定的点是否包含在此 Rectangle 结构内。 |
Contains(Rectangle) |
确定 |
Contains(Int32, Int32) |
确定指定的点是否包含在此 Rectangle 结构内。 |
Contains(Point)
- Source:
- Rectangle.cs
- Source:
- Rectangle.cs
- Source:
- Rectangle.cs
确定指定的点是否包含在此 Rectangle 结构内。
public:
bool Contains(System::Drawing::Point pt);
public readonly bool Contains (System.Drawing.Point pt);
public bool Contains (System.Drawing.Point pt);
member this.Contains : System.Drawing.Point -> bool
Public Function Contains (pt As Point) As Boolean
参数
返回
如果 pt
表示的点包含在此 Rectangle 结构中,此方法将返回 true
;否则将返回 false
。
注解
必须规范化包含的矩形,此方法才能返回准确的结果。
适用于
Contains(Rectangle)
- Source:
- Rectangle.cs
- Source:
- Rectangle.cs
- Source:
- Rectangle.cs
确定 rect
表示的矩形区域是否完全包含在此 Rectangle 结构内。
public:
bool Contains(System::Drawing::Rectangle rect);
public readonly bool Contains (System.Drawing.Rectangle rect);
public bool Contains (System.Drawing.Rectangle rect);
member this.Contains : System.Drawing.Rectangle -> bool
Public Function Contains (rect As Rectangle) As Boolean
参数
返回
如果 rect
表示的矩形区域完全包含在此 Rectangle 结构内,此方法将返回 true
;否则将返回 false
。
示例
下面的代码示例演示 Contains 了 方法和 SystemPens 类。 此示例旨在与 Windows 窗体一起使用。 将此代码粘贴到包含名为 的Button1
按钮的窗体中,从窗体的构造函数或Load方法调用 DrawFirstRectangle
,并将 方法与按钮的 Click 事件相关联Button1_Click
。
private:
[UIPermission(SecurityAction::Demand, Window=UIPermissionWindow::AllWindows)]
void DrawFirstRectangle()
{
Rectangle rectangle1 = Rectangle(70,70,100,150);
ControlPaint::DrawReversibleFrame( rectangle1, SystemColors::Highlight, FrameStyle::Thick );
}
void Button1_Click( Object^ /*sender*/, EventArgs^ /*e*/ )
{
Rectangle rectangle1 = Rectangle(70,70,100,150);
// Get the bounds of the screen.
Rectangle screenRectangle = Screen::PrimaryScreen->Bounds;
// Check to see if the rectangle is within the bounds of the screen.
if ( screenRectangle.Contains( rectangle1 ) )
{
ControlPaint::DrawReversibleFrame( rectangle1, SystemColors::Highlight, FrameStyle::Thick );
// Call the Offset method to move the rectangle.
rectangle1.Offset( 20, 20 );
// Draw the new, offset rectangle.
ControlPaint::DrawReversibleFrame( rectangle1, SystemColors::Highlight, FrameStyle::Thick );
}
}
Rectangle rectangle1 = new Rectangle(70, 70, 100, 150);
private void DrawFirstRectangle()
{
ControlPaint.DrawReversibleFrame(rectangle1,
SystemColors.Highlight, FrameStyle.Thick);
}
private void Button1_Click(object sender, EventArgs e)
{
// Get the bounds of the screen.
Rectangle screenRectangle = Screen.PrimaryScreen.Bounds;
// Check to see if the rectangle is within the bounds of the screen.
if (screenRectangle.Contains(rectangle1))
// If so, erase the previous rectangle.
{
ControlPaint.DrawReversibleFrame(rectangle1,
SystemColors.Highlight, FrameStyle.Thick);
// Call the Offset method to move the rectangle.
rectangle1.Offset(20, 20);
// Draw the new, offset rectangle.
ControlPaint.DrawReversibleFrame(rectangle1,
SystemColors.Highlight, FrameStyle.Thick);
}
}
Dim rectangle1 As New Rectangle(70, 70, 100, 150)
Private Sub DrawFirstRectangle()
ControlPaint.DrawReversibleFrame(rectangle1, _
SystemColors.Highlight, FrameStyle.Thick)
End Sub
Private Sub Button1_Click(ByVal sender As Object, _
ByVal e As EventArgs) Handles Button1.Click
' Get the bounds of the screen.
Dim screenRectangle As Rectangle = Screen.PrimaryScreen.Bounds
' Check to see if the rectangle is within the bounds of the screen.
If (screenRectangle.Contains(rectangle1)) Then
' If so, erase the previous rectangle.
ControlPaint.DrawReversibleFrame(rectangle1, _
SystemColors.Highlight, FrameStyle.Thick)
' Call the Offset method to move the rectangle.
rectangle1.Offset(20, 20)
' Draw the new, offset rectangle.
ControlPaint.DrawReversibleFrame(rectangle1, _
SystemColors.Highlight, FrameStyle.Thick)
End If
End Sub
注解
必须规范化包含的矩形,此方法才能返回准确的结果。
适用于
Contains(Int32, Int32)
- Source:
- Rectangle.cs
- Source:
- Rectangle.cs
- Source:
- Rectangle.cs
确定指定的点是否包含在此 Rectangle 结构内。
public:
bool Contains(int x, int y);
public readonly bool Contains (int x, int y);
public bool Contains (int x, int y);
member this.Contains : int * int -> bool
Public Function Contains (x As Integer, y As Integer) As Boolean
参数
- x
- Int32
要测试的点的 X 坐标。
- y
- Int32
要测试的点的 Y 坐标。
返回
如果 x
和 y
定义的点包含在此 Rectangle 结构中,此方法将返回 true
;否则将返回 false
。
注解
必须规范化包含的矩形,此方法才能返回准确的结果。