Control.ClientRectangle 屬性

定義

取得代表控制區客戶端區域的矩形。

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

屬性值

Rectangle代表控制區的客戶區域。

屬性

範例

以下程式碼範例可自動捲動表單、調整表單大小,並確保調整表單大小後按鈕仍可見。 這個例子要求你有一個 Form 帶有 a Button 名稱 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 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

備註

控制項的客戶端區域是控制項的邊界,減去非客戶端元素,如捲軸列、邊框、標題欄和選單。

由於用戶端座標相對於控制項用戶端區域的左上角,因此此屬性回傳矩形左上角的座標為 (0,0)。 你可以利用此特性取得控制器用戶端區域的大小與座標,用於繪製控制器表面等任務。

欲了解更多關於在控制項上繪圖的資訊,請參閱 「渲染 Windows 表單控制項」。

適用於

另請參閱