Export (0) Print
Expand All
Expand Minimize

Control.ClientRectangle Property

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

[Visual Basic]
Public ReadOnly Property ClientRectangle As Rectangle
[C#]
public Rectangle ClientRectangle {get;}
[C++]
public: __property Rectangle get_ClientRectangle();
[JScript]
public function get ClientRectangle() : Rectangle;

Property Value

A Rectangle that represents the client area of the control.

Remarks

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.

Example

[Visual Basic, C#, C++] The following example enables auto-scrolling for a form, resizes the form, and ensures that a button remains visible after the form is resized. This example assumes that you have a Form with a Button named button2 on it.

[Visual Basic] 
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

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

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

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

Control Class | Control Members | System.Windows.Forms Namespace | ClientSize | DrawMode

Show:
© 2015 Microsoft