Control.SetBoundsCore(Int32, Int32, Int32, Int32, BoundsSpecified) 方法

定義

執行設定這個控制項的指定範圍的工作。

C#
protected virtual void SetBoundsCore (int x, int y, int width, int height, System.Windows.Forms.BoundsSpecified specified);

參數

x
Int32

控制項的新 Left 屬性值。

y
Int32

控制項的新 Top 屬性值。

width
Int32

控制項的新 Width 屬性值。

height
Int32

控制項的新 Height 屬性值。

specified
BoundsSpecified

BoundsSpecified 值的位元組合。

範例

下列程式碼範例會 SetBoundsCore 覆寫 方法,以確保控制項維持固定大小。 此範例會要求您有直接或間接衍生自 類別的 Control 類別。

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

備註

一般而言,對應至參數中未包含 specified 之界限的參數會以其目前值傳入。 例如, Height 屬性的 、 Width 或 或 X Y 屬性 Location 可以使用控制項目前實例的參考傳入。 不過,傳入的所有值都會接受並套用至 控制項。

參數 boundsSpecified 代表應用程式變更之控制項 Bounds 的專案。 例如,如果您變更 Size 控制項的 ,參數 boundsSpecified 值就是 Size 的值 BoundsSpecified 。 不過,如果 Size 已調整 以回應 Dock 所設定的屬性,參數 boundsSpecified 值就是 None 的值 BoundsSpecified

注意

在 Windows Server 2003 系統上,的大小 Form 受限於監視器的最大圖元寬度和高度。

給繼承者的注意事項

在衍生類別中覆 SetBoundsCore(Int32, Int32, Int32, Int32, BoundsSpecified) 寫時,請務必呼叫基類 SetBoundsCore(Int32, Int32, Int32, Int32, BoundsSpecified) 的 方法來強制控制項的界限變更。 衍生類別可以將大小限制新增至 SetBoundsCore(Int32, Int32, Int32, Int32, BoundsSpecified) 方法。

適用於

產品 版本
.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
Windows Desktop 3.0, 3.1, 5, 6, 7

另請參閱