Control.SetClientSizeCore(Int32, Int32) 方法

定義

設定控制項工作區的大小。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

工作區寬度 (單位為像素)。The client area width, in pixels.

y
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.

一般來說,您不應該設定控制項的 ClientSizeTypically, 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 Forms 控制項For more information about drawing on controls, see Rendering a Windows Forms Control.

適用於

另請參閱