Control.ClientRectangle 属性

定义

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

C#
[System.ComponentModel.Browsable(false)]
public System.Drawing.Rectangle ClientRectangle { get; }

属性值

Rectangle

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

属性

示例

下面的代码示例为窗体启用自动滚动,调整窗体大小,并确保在调整窗体大小后按钮保持可见。 此示例要求你有一个FormButton具有命名的名称button2

C#
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);
}

注解

控件的工作区是控件的边界,减去滚动条、边框、标题栏和菜单等非封闭元素。

由于客户端坐标相对于控件工作区的左上角,因此此属性返回的矩形左上角的坐标 (0,0) 。 可以使用此属性获取控件的工作区的大小和坐标,这些任务如在控件图面上绘制。

有关绘制控件的详细信息,请参阅呈现Windows 窗体控件

适用于

产品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
Windows Desktop 3.0, 3.1, 5, 6, 7

另请参阅