Control.ClientRectangle Control.ClientRectangle Control.ClientRectangle Control.ClientRectangle Property

定义

获取表示控件的工作区的矩形。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

属性值

Rectangle,它表示控件的工作区。A 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. 此示例要求具有一个Form Button具有命名button2的。This 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 窗体控件For more information about drawing on controls, see Rendering a Windows Forms Control.

适用于

另请参阅