Rectangle.Contains Método

Definição

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

Sobrecargas

Nome Description
Contains(Point)

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

Contains(Rectangle)

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

Contains(Int32, Int32)

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

Contains(Point)

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

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 a ser testado.

Retornos

Esse método retornará true se o ponto representado por pt ele estiver contido nessa Rectangle estrutura; 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)

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

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 a ser testado.

Retornos

Esse método retornará true se a região retangular representada por rect estiver totalmente contida nessa Rectangle estrutura; 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 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)

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

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 ser testado.

y
Int32

A coordenada y do ponto a ser testado.

Retornos

Esse método retornará true se o ponto definido e yx estiver contido nessa Rectangle estrutura; caso contráriofalse.

Comentários

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

Aplica-se a