Rectangle.Contains Metoda

Definicja

Określa, czy określony punkt znajduje się w regionie prostokątnym zdefiniowanym przez ten Rectangleelement .

Przeciążenia

Contains(Point)

Określa, czy określony punkt znajduje się w tej Rectangle strukturze.

Contains(Rectangle)

Określa, czy prostokątny region reprezentowany przez rect element jest całkowicie zawarty w tej Rectangle strukturze.

Contains(Int32, Int32)

Określa, czy określony punkt znajduje się w tej Rectangle strukturze.

Contains(Point)

Źródło:
Rectangle.cs
Źródło:
Rectangle.cs
Źródło:
Rectangle.cs

Określa, czy określony punkt znajduje się w tej Rectangle strukturze.

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

Parametry

pt
Point

Element Point do przetestowania.

Zwraca

Ta metoda zwraca true wartość , jeśli punkt reprezentowany przez pt element jest zawarty w tej Rectangle strukturze; w przeciwnym razie false.

Uwagi

Aby ta metoda zwracała dokładne wyniki, należy znormalizować zawierający prostokąt.

Dotyczy

Contains(Rectangle)

Źródło:
Rectangle.cs
Źródło:
Rectangle.cs
Źródło:
Rectangle.cs

Określa, czy prostokątny region reprezentowany przez rect element jest całkowicie zawarty w tej Rectangle strukturze.

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

Parametry

rect
Rectangle

Element Rectangle do przetestowania.

Zwraca

Ta metoda zwraca wartość true , jeśli prostokątny region reprezentowany przez rect element jest całkowicie zawarty w tej Rectangle strukturze; w przeciwnym razie false.

Przykłady

Poniższy przykład kodu przedstawia metodę Contains i klasę SystemPens . Ten przykład jest przeznaczony do użycia z formularzem systemu Windows. Wklej ten kod w formularzu zawierającym przycisk o nazwie Button1, wywołanie DrawFirstRectangle z konstruktora lub Load metody formularza i skojarzenie Button1_Click metody ze zdarzeniem przycisku 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

Uwagi

Aby ta metoda zwracała dokładne wyniki, należy znormalizować zawierający prostokąt.

Dotyczy

Contains(Int32, Int32)

Źródło:
Rectangle.cs
Źródło:
Rectangle.cs
Źródło:
Rectangle.cs

Określa, czy określony punkt znajduje się w tej Rectangle strukturze.

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

Parametry

x
Int32

Współrzędna x punktu do przetestowania.

y
Int32

Współrzędna y punktu do przetestowania.

Zwraca

Ta metoda zwraca true wartość , jeśli punkt zdefiniowany przez x element i y jest zawarty w tej Rectangle strukturze; w przeciwnym razie false.

Uwagi

Aby ta metoda zwracała dokładne wyniki, należy znormalizować zawierający prostokąt.

Dotyczy