共用方式為


Control.CreateParams 屬性

定義

當控制句柄建立時,會取得所需的建立參數。

protected:
 virtual property System::Windows::Forms::CreateParams ^ CreateParams { System::Windows::Forms::CreateParams ^ get(); };
protected virtual System.Windows.Forms.CreateParams CreateParams { get; }
member this.CreateParams : System.Windows.Forms.CreateParams
Protected Overridable ReadOnly Property CreateParams As CreateParams

屬性值

CreateParams A 包含在建立控制項的 handle 時所需的建立參數。

範例

以下程式碼範例擴展 CreateParams 了衍生類別的 Button 特性。 CreateParams.Style屬性被改變,導致按鈕顯示的Icon是一個而非。Image 這個例子要求你有一個繼承自該 Button 類別的類別。

virtual System::Windows::Forms::CreateParams^ get() override
{
   
   // Extend the CreateParams property of the Button class.
   System::Windows::Forms::CreateParams^ cp = __super::CreateParams;

   // Update the button Style.
   cp->Style |= 0x00000040; // BS_ICON value
   return cp;
}
protected override CreateParams CreateParams
{
    get
    {
        // Extend the CreateParams property of the Button class.
        CreateParams cp = base.CreateParams;
        // Update the button Style.
        cp.Style |= 0x00000040; // BS_ICON value

        return cp;
    }
}

Protected Overrides ReadOnly Property CreateParams() As System.Windows.Forms.CreateParams
    Get
        Dim SecPerm As New SecurityPermission(SecurityPermissionFlag.UnmanagedCode)
        SecPerm.Demand()

        ' Extend the CreateParams property of the Button class.
        Dim cp As System.Windows.Forms.CreateParams = MyBase.CreateParams
        ' Update the button Style.
        cp.Style = cp.Style Or &H40 ' BS_ICON value

        Return cp
    End Get
End Property

備註

CreateParams該屬性不應被覆寫,也不應用來調整你衍生控制的屬性。 像 、 CreateParams.Width、 等屬性CreateParams.Caption應該由你控制項中對應的屬性設定,例如 Control.TextControl.WidthControl.HeightCreateParams.Height 和 。 CreateParams只有當你要包裝標準 Windows 控制類別,或是設定 Windows Forms 命名空間沒有提供的樣式時,才應該擴充。 欲了解更多關於建立控制參數的資訊,請參閱 and CreateWindowExCreateWindow數及 CREATESTRUCT 結構文件。

給繼承者的注意事項

在導出類別中覆寫該 CreateParams 屬性時,請使用基底類別的 CreateParams 特性來擴充基底實作。 否則,你必須提供所有的實作。

適用於

另請參閱