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

表示控制項工作區的 Rectangle

屬性

範例

下列程式碼範例會啟用表單的自動捲動、調整表單大小,並確保表單調整大小之後,按鈕仍保持可見狀態。 此範例要求您在上具有 Form 具名 button2Button

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

備註

控制項的工作區是控制項的界限,減去非client 元素,例如捲軸、框線、標題列和功能表。

因為用戶端座標相對於控制項工作區的左上角,所以這個屬性傳回之矩形左上角的座標 (0,0) 。 您可以使用這個屬性來取得控制項工作區的大小和座標,例如在控制項介面上繪製的工作。

如需在控制項上繪製的詳細資訊,請參閱轉譯Windows Forms控制項

適用於

另請參閱