Control.ClientRectangle 屬性

定義

取得表示控制項工作區的矩形。

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

屬性值

Rectangle

表示控制項工作區的 Rectangle

屬性

範例

下列程式碼範例會啟用表單的自動捲動、調整表單大小,並確保表單調整大小之後,按鈕仍保持可見狀態。 此範例要求您在上具有 Form 具名 button2Button

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

備註

控制項的工作區是控制項的界限,減去非client 元素,例如捲軸、框線、標題列和功能表。

因為用戶端座標相對於控制項工作區的左上角,所以這個屬性傳回之矩形左上角的座標 (0,0) 。 您可以使用這個屬性來取得控制項工作區的大小和座標,例如在控制項介面上繪製的工作。

如需在控制項上繪製的詳細資訊,請參閱轉譯Windows Forms控制項

適用於

產品 版本
.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

另請參閱