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,包含建立控制項之控制代碼時所需的建立參數。

範例

下列程式碼範例會 CreateParams 擴充衍生類別的 Button 屬性。 屬性 CreateParams.Style 已變更,這會導致按鈕顯示 而非 IconImage 。 此範例會要求您有繼承自 類別的 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.Caption 屬性應該由 控制項中的對應屬性設定,例如 Control.TextControl.WidthControl.HeightCreateParams.HeightCreateParams.Width CreateParams只有在您包裝標準 Windows 控制項類別或設定Windows Forms命名空間未提供的樣式時,才應該擴充 。 如需建立控制項參數的詳細資訊,請參閱 CreateWindowCreateWindowEx 函式和 CREATESTRUCT 結構檔。

給繼承者的注意事項

在衍生類別中覆 CreateParams 寫屬性時,請使用基類的 CreateParams 屬性來擴充基底實作。 否則,您必須提供所有實作。

適用於

另請參閱