Control.SetClientSizeCore 方法

设置控件的工作区的大小。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Protected Overridable Sub SetClientSizeCore ( _
    x As Integer, _
    y As Integer _
)
用法
Dim x As Integer
Dim y As Integer

Me.SetClientSizeCore(x, y)
protected virtual void SetClientSizeCore (
    int x,
    int y
)
protected:
virtual void SetClientSizeCore (
    int x, 
    int y
)
protected void SetClientSizeCore (
    int x, 
    int y
)
protected function SetClientSizeCore (
    x : int, 
    y : int
)

参数

  • x
    工作区宽度(以像素为单位)。
  • y
    工作区高度(以像素为单位)。

备注

工作区在 (0, 0) 位置开始,并扩展到(x,y)位置。

通常,不要设置控件的 ClientSize

给继承者的说明 在派生类中重写 SetClientSizeCore 时,请确保调用了基类的 SetClientSizeCore 方法,以便调整 ClientSize 属性。 有关在控件上绘制的更多信息,请参见 呈现 Windows 窗体控件

示例

下面的代码示例重写 SetClientSizeCore 方法,以确保控件保持正方形。该示例要求有从 Control 类直接或间接派生的类。

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

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

Control 类
Control 成员
System.Windows.Forms 命名空间
ClientSize