Rectangle.Contains Método

Definição

Determina se o ponto especificado está contido dentro da região retangular definida por este Rectangle.

Sobrecargas

Contains(Point)

Determina se o ponto especificado está contido nessa estrutura Rectangle.

Contains(Rectangle)

Determina se a região retangular representada por rect está inteiramente contida dentro desta estrutura Rectangle.

Contains(Int32, Int32)

Determina se o ponto especificado está contido nessa estrutura Rectangle.

Contains(Point)

Origem:
Rectangle.cs
Origem:
Rectangle.cs
Origem:
Rectangle.cs

Determina se o ponto especificado está contido nessa estrutura 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

Parâmetros

pt
Point

O Point a ser testado.

Retornos

Esse método retorna true se o ponto representado por pt está contido nessa estrutura Rectangle; caso contrário, false.

Comentários

O retângulo que contém deve ser normalizado para que esse método retorne resultados precisos.

Aplica-se a

Contains(Rectangle)

Origem:
Rectangle.cs
Origem:
Rectangle.cs
Origem:
Rectangle.cs

Determina se a região retangular representada por rect está inteiramente contida dentro desta estrutura 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

Parâmetros

rect
Rectangle

O Rectangle a ser testado.

Retornos

Este método retornará true se a região retangular representada por rect estiver inteiramente contida dentro desta estrutura Rectangle; caso contrário, false.

Exemplos

O exemplo de código a seguir demonstra o Contains método e a SystemPens classe . Este exemplo foi projetado para uso com um Formulário do Windows. Cole esse código em um formulário que contém um botão chamado Button1, chame DrawFirstRectangle do construtor ou Load método do formulário e associe o Button1_Click método ao evento do Click botão.

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

Comentários

O retângulo que contém deve ser normalizado para que esse método retorne resultados precisos.

Aplica-se a

Contains(Int32, Int32)

Origem:
Rectangle.cs
Origem:
Rectangle.cs
Origem:
Rectangle.cs

Determina se o ponto especificado está contido nessa estrutura 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

Parâmetros

x
Int32

A coordenada X do ponto a ser testado.

y
Int32

A coordenada Y do ponto a ser testado.

Retornos

Este método retornará true se o ponto definido por x e y estiver contido dentro desta estrutura Rectangle; caso contrário, false.

Comentários

O retângulo que contém deve ser normalizado para que esse método retorne resultados precisos.

Aplica-se a