Rectangle.Contains Metode

Definisi

Menentukan apakah titik yang ditentukan terkandung dalam wilayah persegi panjang yang ditentukan oleh ini Rectangle.

Overload

Contains(Point)

Menentukan apakah titik yang ditentukan terkandung dalam struktur ini Rectangle .

Contains(Rectangle)

Menentukan apakah wilayah persegi panjang yang diwakili oleh rect sepenuhnya terkandung dalam struktur ini Rectangle .

Contains(Int32, Int32)

Menentukan apakah titik yang ditentukan terkandung dalam struktur ini Rectangle .

Contains(Point)

Sumber:
Rectangle.cs
Sumber:
Rectangle.cs
Sumber:
Rectangle.cs

Menentukan apakah titik yang ditentukan terkandung dalam struktur ini 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

Parameter

pt
Point

Yang akan diuji Point .

Mengembalikan

Metode ini mengembalikan true jika titik yang diwakili oleh pt terkandung dalam struktur ini Rectangle ; jika tidak false.

Keterangan

Persegi panjang yang berisi harus dinormalisasi agar metode ini mengembalikan hasil yang akurat.

Berlaku untuk

Contains(Rectangle)

Sumber:
Rectangle.cs
Sumber:
Rectangle.cs
Sumber:
Rectangle.cs

Menentukan apakah wilayah persegi panjang yang diwakili oleh rect sepenuhnya terkandung dalam struktur ini 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

Parameter

rect
Rectangle

Yang akan diuji Rectangle .

Mengembalikan

Metode ini mengembalikan true jika wilayah persegi panjang yang diwakili oleh rect sepenuhnya terkandung dalam struktur ini Rectangle ; jika tidak false.

Contoh

Contoh kode berikut menunjukkan Contains metode dan SystemPens kelas . Contoh ini dirancang untuk digunakan dengan Formulir Windows. Tempelkan kode ini ke dalam formulir yang berisi tombol bernama , panggil DrawFirstRectangle dari konstruktor atau Load metode formulir, dan kaitkan Button1_Click metode dengan peristiwa tombolClick.Button1

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

Keterangan

Persegi panjang yang berisi harus dinormalisasi agar metode ini mengembalikan hasil yang akurat.

Berlaku untuk

Contains(Int32, Int32)

Sumber:
Rectangle.cs
Sumber:
Rectangle.cs
Sumber:
Rectangle.cs

Menentukan apakah titik yang ditentukan terkandung dalam struktur ini 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

Parameter

x
Int32

Koordinat x titik untuk diuji.

y
Int32

Koordinat y dari titik untuk diuji.

Mengembalikan

Metode ini mengembalikan true jika titik yang ditentukan oleh x dan y terkandung dalam struktur ini Rectangle ; jika tidak false.

Keterangan

Persegi panjang yang berisi harus dinormalisasi agar metode ini mengembalikan hasil yang akurat.

Berlaku untuk