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 Forms 控制項For more information about drawing on controls, see Rendering a Windows Forms Control.

適用於

另請參閱