Rectangle.Contains Método

Definição

Determina se o ponto especificado está contido dentro da região retangular definida por este Rectangle.Determines if the specified point is contained within the rectangular region defined by this Rectangle.

Sobrecargas

Contains(Point)

Determina se o ponto especificado está contido nessa estrutura Rectangle.Determines if the specified point is contained within this Rectangle structure.

Contains(Rectangle)

Determina se a região retangular representada por rect está inteiramente contida dentro desta estrutura Rectangle.Determines if the rectangular region represented by rect is entirely contained within this Rectangle structure.

Contains(Int32, Int32)

Determina se o ponto especificado está contido nessa estrutura Rectangle.Determines if the specified point is contained within this Rectangle structure.

Contains(Point)

Determina se o ponto especificado está contido nessa estrutura Rectangle.Determines if the specified point is contained within this Rectangle structure.

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 a ser testado.The Point to test.

Retornos

Esse método retorna true se o ponto representado por pt está contido nessa estrutura Rectangle; caso contrário, false.This method returns true if the point represented by pt is contained within this Rectangle structure; otherwise false.

Comentários

O retângulo de contenção deve ser normalizado para que esse método retorne resultados precisos.The containing rectangle must be normalized for this method to return accurate results.

Contains(Rectangle)

Determina se a região retangular representada por rect está inteiramente contida dentro desta estrutura Rectangle.Determines if the rectangular region represented by rect is entirely contained within this Rectangle structure.

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 a ser testado.The Rectangle to test.

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.This method returns true if the rectangular region represented by rect is entirely contained within this Rectangle structure; otherwise false.

Exemplos

O exemplo de código a seguir demonstra o método Contains e a classe SystemPens.The following code example demonstrates the Contains method and the SystemPens class. Este exemplo foi projetado para uso com um Windows Form.This example is designed for use with a Windows Form. Cole esse código em um formulário que contém um botão chamado Button1, chame DrawFirstRectangle do construtor do formulário ou do método Load e associe o método Button1_Click ao evento Click do botão.Paste this code into a form that contains a button named Button1, call DrawFirstRectangle from the form's constructor or Load method, and associate the Button1_Click method with the button's Click event.

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 de contenção deve ser normalizado para que esse método retorne resultados precisos.The containing rectangle must be normalized for this method to return accurate results.

Contains(Int32, Int32)

Determina se o ponto especificado está contido nessa estrutura Rectangle.Determines if the specified point is contained within this Rectangle structure.

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.The x-coordinate of the point to test.

y
Int32

A coordenada Y do ponto a ser testado.The y-coordinate of the point to test.

Retornos

Este método retornará true se o ponto definido por x e y estiver contido dentro desta estrutura Rectangle; caso contrário, false.This method returns true if the point defined by x and y is contained within this Rectangle structure; otherwise false.

Comentários

O retângulo de contenção deve ser normalizado para que esse método retorne resultados precisos.The containing rectangle must be normalized for this method to return accurate results.

Aplica-se a