Share via


Control.SetBoundsCore 方法

执行设置该控件的指定边界的工作。

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

语法

声明
Protected Overridable Sub SetBoundsCore ( _
    x As Integer, _
    y As Integer, _
    width As Integer, _
    height As Integer, _
    specified As BoundsSpecified _
)
用法
Dim x As Integer
Dim y As Integer
Dim width As Integer
Dim height As Integer
Dim specified As BoundsSpecified

Me.SetBoundsCore(x, y, width, height, specified)
protected virtual void SetBoundsCore (
    int x,
    int y,
    int width,
    int height,
    BoundsSpecified specified
)
protected:
virtual void SetBoundsCore (
    int x, 
    int y, 
    int width, 
    int height, 
    BoundsSpecified specified
)
protected void SetBoundsCore (
    int x, 
    int y, 
    int width, 
    int height, 
    BoundsSpecified specified
)
protected function SetBoundsCore (
    x : int, 
    y : int, 
    width : int, 
    height : int, 
    specified : BoundsSpecified
)

参数

  • x
    控件的新 Left 属性值。
  • y
    控件的新 Top 属性值。
  • width
    控件的新 Width 属性值。
  • height
    控件的新 Height 属性值。

备注

通常,当传入与未包括在 specified 参数中的边界对应的参数时,会使用它们的当前值。例如,Location 属性的 HeightWidthXY 属性可以用对控件的当前实例的引用传入。但是,所有传入的值都是有效的,并应用到控件中。

boundsSpecified 参数表示由应用程序更改了的控件 Bounds 的元素。例如,如果更改控件的 Size,则 boundsSpecified 参数值为 BoundsSpecifiedSize 值。但是,如果为响应正在设置的 Dock 属性而调整了 Size,则 boundsSpecified 参数值为 BoundsSpecifiedNone 值。

给继承者的说明 在派生类中重写 SetBoundsCore 时,请确保调用了基类的 SetBoundsCore 方法,以强制更改控件的边界。派生类可以在 SetBoundsCore 方法中添加大小限制。

示例

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

Protected Overrides Sub SetBoundsCore(x As Integer, _
  y As Integer, width As Integer, _
  height As Integer, specified As BoundsSpecified)
   ' Set a fixed height and width for the control.
   MyBase.SetBoundsCore(x, y, 150, 75, specified)
End Sub
protected override void SetBoundsCore(int x, int y, 
   int width, int height, BoundsSpecified specified)
{
   // Set a fixed height and width for the control.
   base.SetBoundsCore(x, y, 150, 75, specified);
}
protected:
   virtual void SetBoundsCore( int x, int y, int width, int height, BoundsSpecified specified ) override
   {
      // Set a fixed height and width for the control.
      UserControl::SetBoundsCore( x, y, 150, 75, specified );
   }
protected void SetBoundsCore(int x, int y, int width, int height,
    BoundsSpecified specified)
{
    // Set a fixed height and width for the control.
    super.SetBoundsCore(x, y, 150, 75, specified);
} //SetBoundsCore

平台

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 命名空间
SetBounds
Bounds
Layout