Rectangle.Contains 方法

定义

确定指定点是否包含在由此 Rectangle定义的矩形区域中。

重载

名称 说明
Contains(Point)

确定指定点是否包含在此 Rectangle 结构中。

Contains(Rectangle)

确定所表示 rect 的矩形区域是否完全包含在此 Rectangle 结构中。

Contains(Int32, Int32)

确定指定点是否包含在此 Rectangle 结构中。

Contains(Point)

Source:
Rectangle.cs
Source:
Rectangle.cs
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
Point

Point 测试的。

返回

此方法返回 true 由此结构表示的 pt 点是否包含在此 Rectangle 结构中;否则 false为 。

注解

必须规范化包含的矩形,以便此方法返回准确的结果。

适用于

Contains(Rectangle)

Source:
Rectangle.cs
Source:
Rectangle.cs
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

Rectangle 测试的。

返回

如果表示的矩形区域完全包含在此结构中,则此方法返回;否则为 < a0/>。

示例

下面的代码示例演示了 Contains 方法和 SystemPens 类。 此示例旨在与 Windows 窗体一起使用。 将此代码粘贴到包含名为Button1按钮的窗体中,从窗体的构造函数或DrawFirstRectangle方法调用Load,并将该方法与按钮Button1_Click的事件相关联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
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 坐标。

返回

此方法返回truexy结构中定义并Rectangle包含的点;否则false为 。

注解

必须规范化包含的矩形,以便此方法返回准确的结果。

适用于