Control.CreateParams Control.CreateParams Control.CreateParams Control.CreateParams Property

定義

建立控制代碼時,取得必要的建立參數。Gets the required creation parameters when the control handle is created.

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 CreateParams that contains the required creation parameters when the handle to the control is created.

範例

下列程式碼範例會擴充CreateParams Button衍生類別的屬性。The following code example extends the CreateParams property of a Button derived class. 屬性已變更,這會導致按鈕Icon顯示,而不Image是。 CreateParams.StyleThe CreateParams.Style property is changed, which causes the button to display an Icon rather than an Image. 這個範例需要您具有繼承自Button類別的類別。This example requires that you have a class that inherits from the Button class.

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
    {
        new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();

        // 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屬性不應該覆寫並用來調整衍生控制項的屬性。The CreateParams property should not be overridden and used to adjust the properties of your derived control. CreateParams.Caption屬性(例如Control.TextCreateParams.Width Control.Width和) Control.Height應由控制項中的對應屬性設定,例如、和。 CreateParams.HeightProperties such as the CreateParams.Caption, CreateParams.Width, and CreateParams.Height should be set by the corresponding properties in your control such as Control.Text, Control.Width and Control.Height. 只有CreateParams當您包裝標準 Windows 控制項類別,或設定 Windows Forms 命名空間未提供的樣式時,才應該擴充。The CreateParams should only be extended when you are wrapping a standard Windows control class or to set styles not provided by the Windows Forms namespace. 如需建立控制項參數的詳細資訊,請CreateWindow參閱CreateWindowEx和函式和CREATESTRUCT結構檔。For more information about creating control parameters, see the CreateWindow and CreateWindowEx functions and the CREATESTRUCT structure documentation.

給繼承者的注意事項

覆寫衍生CreateParams類別中的屬性時, 請使用基類的CreateParams屬性來擴充基底實作為。When overriding the CreateParams property in a derived class, use the base class's CreateParams property to extend the base implementation. 否則, 您必須提供所有的實作為。Otherwise, you must provide all the implementation.

安全性

SecurityPermission
取得屬性值時,讓立即呼叫端呼叫非受控碼。for the immediate caller to call unmanaged code when getting the property value. 相關聯的列舉:UnmanagedCodeAssociated enumeration: UnmanagedCode

適用於

另請參閱