Export (0) Print
Expand All
Expand Minimize

Control::ClientRectangle Property

Gets the rectangle that represents the client area of the control.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

[BrowsableAttribute(false)]
public:
property Rectangle ClientRectangle {
	Rectangle get ();
}

Property Value

Type: System.Drawing::Rectangle
A Rectangle that represents the client area of the control.

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.

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.

For more information about drawing on controls, see Rendering a Windows Forms 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. 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 );
   }

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft