Control.ClientRectangle Properti

Definisi

Mendapatkan persegi panjang yang mewakili area klien kontrol.

public:
 property System::Drawing::Rectangle ClientRectangle { System::Drawing::Rectangle get(); };
[System.ComponentModel.Browsable(false)]
public System.Drawing.Rectangle ClientRectangle { get; }
[<System.ComponentModel.Browsable(false)>]
member this.ClientRectangle : System.Drawing.Rectangle
Public ReadOnly Property ClientRectangle As Rectangle

Nilai Properti

Rectangle yang mewakili area klien kontrol.

Atribut

Contoh

Contoh kode berikut memungkinkan pengguliran otomatis untuk formulir, mengubah ukuran formulir, dan memastikan bahwa tombol tetap terlihat setelah formulir diubah ukurannya. Contoh ini mengharuskan Anda memiliki Form dengan nama Buttonbutton2 di dalamnya.

private:
   void ResizeForm()
   {
      
      // Enable auto-scrolling for the form.
      this->AutoScroll = true;
      
      // Resize the form.
      Rectangle r = this->ClientRectangle;
      
      // Subtract 100 pixels from each side of the Rectangle.
      r.Inflate(  -100, -100 );
      this->Bounds = this->RectangleToScreen( r );
      
      // Make sure button2 is visible.
      this->ScrollControlIntoView( button2 );
   }
private void ResizeForm()
{
   // Enable auto-scrolling for the form.
   this.AutoScroll = true;

   // Resize the form.
   Rectangle r = this.ClientRectangle;
   // Subtract 100 pixels from each side of the Rectangle.
   r.Inflate(-100, -100);
   this.Bounds = this.RectangleToScreen(r);

   // Make sure button2 is visible.
   this.ScrollControlIntoView(button2);
}
Private Sub ResizeForm()
   ' Enable auto-scrolling for the form.
   Me.AutoScroll = True
   
   ' Resize the form.
   Dim r As Rectangle = Me.ClientRectangle
   ' Subtract 100 pixels from each side of the Rectangle.
   r.Inflate(- 100, - 100)
   Me.Bounds = Me.RectangleToScreen(r)
   
   ' Make sure button2 is visible.
   Me.ScrollControlIntoView(button2)
End Sub

Keterangan

Area klien kontrol adalah batas kontrol, dikurangi elemen nonkelola seperti bilah gulir, batas, bilah judul, dan menu.

Karena koordinat klien relatif terhadap sudut kiri atas area klien kontrol, koordinat sudut kiri atas persegi panjang yang dikembalikan oleh properti ini adalah (0,0). Anda dapat menggunakan properti ini untuk mendapatkan ukuran dan koordinat area klien kontrol untuk tugas seperti menggambar di permukaan kontrol.

Untuk informasi selengkapnya tentang menggambar pada kontrol, lihat Merender Kontrol Formulir Windows.

Berlaku untuk

Lihat juga