Control.ClientRectangle 屬性

定義

取得表示控制項工作區的矩形。Gets the rectangle that represents the client area of the control.

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

屬性值

表示控制項工作區的 RectangleA Rectangle that represents the client area of the control.

屬性

範例

下列程式碼範例會針對表單啟用自動滾動、調整表單的大小,並確保按鈕在調整大小後仍然可見。The following code example enables auto-scrolling for a form, resizes the form, and ensures that a button remains visible after the form is resized. 此範例會要求您在其上具有名為 button2Button FormThis example requires that you have a Form with a Button named button2 on it.

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

備註

控制項的工作區是控制項的範圍,減去非工作專案(例如捲軸、框線、標題列和功能表)。The client area of a control is the bounds of the control, minus the nonclient elements such as scroll bars, borders, title bars, and menus.

由於用戶端座標相對於控制項工作區的左上角,此屬性所傳回之矩形左上角的座標為(0,0)。Because client coordinates are relative to the upper-left corner of the client area of the control, the coordinates of the upper-left corner of the rectangle returned by this property are (0,0). 您可以使用這個屬性,取得控制項之工作區的大小和座標,例如在控制項介面上繪製。You can use this property to obtain the size and coordinates of the client area of the control for tasks such as drawing on the surface of the control.

如需有關在控制項上繪製的詳細資訊,請參閱轉譯Windows Forms 控制項For more information about drawing on controls, see Rendering a Windows Forms Control.

適用於

另請參閱