Rectangle.Contains Método

Definição

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

Sobrecargas

Name Description
Contains(Point)

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

Contains(Rectangle)

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

Contains(Int32, Int32)

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

Contains(Point)

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

public:
 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 teste.

Devoluções

Este método retorna true se o ponto representado por pt estiver contido nesta Rectangle estrutura; caso contrário false.

Observações

O retângulo contendo deve ser normalizado para que este método devolva resultados precisos.

Aplica-se a

Contains(Rectangle)

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

public:
 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 teste.

Devoluções

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

Exemplos

O seguinte exemplo de código demonstra o Contains método e a SystemPens classe. Este exemplo foi concebido para uso com um Windows Form. Cole este código num formulário que contenha um botão chamado Button1, chamada 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

Observações

O retângulo contendo deve ser normalizado para que este método devolva resultados precisos.

Aplica-se a

Contains(Int32, Int32)

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

public:
 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 testar.

y
Int32

A coordenada y do ponto a testar.

Devoluções

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

Observações

O retângulo contendo deve ser normalizado para que este método devolva resultados precisos.

Aplica-se a