Control.ClientRectangle 属性

获取表示控件的工作区的矩形。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public ReadOnly Property ClientRectangle As Rectangle
用法
Dim instance As Control
Dim value As Rectangle

value = instance.ClientRectangle
public Rectangle ClientRectangle { get; }
public:
property Rectangle ClientRectangle {
    Rectangle get ();
}
/** @property */
public Rectangle get_ClientRectangle ()
public function get ClientRectangle () : Rectangle

属性值

一个 Rectangle,它表示控件的工作区。

备注

控件的工作区是控件的边界减去非工作区元素(如滚动条、边框、标题栏和菜单)。

由于工作区坐标是相对于控件工作区的左上角而言的,所以该属性所返回的矩形的左上角坐标是 (0,0)。可以使用该属性为诸如在控件的表面上绘制之类的任务获得控件工作区的大小和坐标。

有关在控件上绘制的更多信息,请参见 呈现 Windows 窗体控件

示例

下面的代码示例启用窗体的自动滚动、调整窗体的大小并确保在调整窗体的大小后按钮仍然可见。该示例要求有一个 Form,其上带有名为 button2Button

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
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 void ResizeForm()
{
    // Enable auto-scrolling for the form.
    this.set_AutoScroll(true);
    // Resize the form.
    Rectangle r = this.get_ClientRectangle();
    // Subtract 100 pixels from each side of the Rectangle.
    r.Inflate(-100, -100);
    this.set_Bounds(this.RectangleToScreen(r));
    // Make sure button2 is visible.
    this.ScrollControlIntoView(button2);
} //ResizeForm

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

Control 类
Control 成员
System.Windows.Forms 命名空间
ClientSize
DrawMode