Control.SetClientSizeCore(Int32, Int32) Method

Definition

Sets the size of the client area of the control.

C#
protected virtual void SetClientSizeCore(int x, int y);

Parameters

x
Int32

The client area width, in pixels.

y
Int32

The client area height, in pixels.

Examples

The following code example overrides the SetClientSizeCore method to ensure that the control remains square. This example requires that you have a class that is either directly or indirectly derived from the Control class.

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

Remarks

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

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

Notes to Inheritors

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

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

Applies to

Product Versions
.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, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

See also