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,它表示控件的工作区。

属性

示例

下面的代码示例为窗体启用自动滚动,调整窗体大小,并确保在调整窗体大小后按钮保持可见。 此示例要求你有一个FormButton具有命名的名称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 窗体控件

适用于

另请参阅