Control.SetClientSizeCore(Int32, Int32) Control.SetClientSizeCore(Int32, Int32) Control.SetClientSizeCore(Int32, Int32) Control.SetClientSizeCore(Int32, Int32) Method

定义

设置控件的工作区的大小。Sets the size of the client area of the control.

protected:
 virtual void SetClientSizeCore(int x, int y);
protected virtual void SetClientSizeCore (int x, int y);
abstract member SetClientSizeCore : int * int -> unit
override this.SetClientSizeCore : int * int -> unit
Protected Overridable Sub SetClientSizeCore (x As Integer, y As Integer)

参数

x
Int32 Int32 Int32 Int32

工作区宽度(以像素为单位)。The client area width, in pixels.

y
Int32 Int32 Int32 Int32

工作区高度(以像素为单位)。The client area height, in pixels.

示例

下面的代码示例重写SetClientSizeCore方法,以确保控件保持为方形。The following code example overrides the SetClientSizeCore method to ensure that the control remains square. 此示例要求具有直接或间接从Control类派生的类。This example requires that you have a class that is either directly or indirectly derived from the Control class.

protected:
   virtual void SetClientSizeCore( int x, int y ) override
   {
      // Keep the client size square.
      if ( x > y )
      {
         UserControl::SetClientSizeCore( x, x );
      }
      else
      {
         UserControl::SetClientSizeCore( y, y );
      }
   }
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);
   }
}
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

注解

工作区从(0,0)位置开始,并延伸到(xy)位置。The client area starts at the (0, 0) location and extends to the (x, y) location.

通常,不应设置ClientSize控件的。Typically, you should not set the ClientSize of the control.

继承者说明

当在SetClientSizeCore(Int32, Int32)派生类中重写时,请确保调用基类的SetClientSizeCore(Int32, Int32)方法,以便ClientSize调整属性。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.

有关在控件上绘制的详细信息,请参阅呈现 Windows 窗体控件For more information about drawing on controls, see Rendering a Windows Forms Control.

适用于

另请参阅