Export (0) Print
Expand All
Expand Minimize

Control.SetClientSizeCore Method

Sets the size of the client area of the control.

[Visual Basic]
Protected Overridable Sub SetClientSizeCore( _
   ByVal x As Integer, _
   ByVal y As Integer _
)
[C#]
protected virtual void SetClientSizeCore(
 int x,
 int y
);
[C++]
protected: virtual void SetClientSizeCore(
 int x,
 int y
);
[JScript]
protected function SetClientSizeCore(
   x : int,
 y : int
);

Parameters

x
The client area width, in pixels.
y
The client area height, in pixels.

Remarks

The client area starts at the (0, 0) location and extends to the (x, y) location.

Typically, you do not set the ClientSize of the control.

Notes to Inheritors:  When overriding SetClientSizeCore in a derived class, be sure to call the base class's SetClientSizeCore method so that the ClientSize property is adjusted.

For more information about drawing on controls, see Rendering a Windows Forms Control.

Example

[Visual Basic, C#, C++] The following example overrides the SetClientSizeCore method to ensure that the control remains square. This example assumes you have a class that is either directly or indirectly derived from the Control class.

[Visual Basic] 
Protected Overrides Sub SetClientSizeCore(x As Integer, y As Integer)
   ' Keep the client size square.
   If x > y Then
      MyBase.SetClientSizeCore(x, x)
   Else
      MyBase.SetClientSizeCore(y, y)
   End If
End Sub

[C#] 
protected override void SetClientSizeCore(int x, int y)
{
   // Keep the client size square.
   if(x > y)
   {
      base.SetClientSizeCore(x, x);
   }
   else
   {
      base.SetClientSizeCore(y, y);
   }
}

[C++] 
protected:
   void SetClientSizeCore(int x, int y) {
      // Keep the client size square.
      if (x > y) {
         UserControl::SetClientSizeCore(x, x);
      } else {
         UserControl::SetClientSizeCore(y, y);
      }
   }

[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

See Also

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

Show:
© 2014 Microsoft