Control.CreateParams Property


获取创建控件句柄时所需要的创建参数。Gets the required creation parameters when the control handle is created.

 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

Property Value


CreateParams,包含创建控件的句柄时所需的创建参数。A CreateParams that contains the required creation parameters when the handle to the control is created.


下面的代码示例扩展了 Button 派生类的 CreateParams 属性。The following code example extends the CreateParams property of a Button derived class. CreateParams.Style 属性已更改,这会导致按钮显示 Icon 而不是 ImageThe 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
        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
        Dim SecPerm As New SecurityPermission(SecurityPermissionFlag.UnmanagedCode)

        ' 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.CaptionCreateParams.WidthCreateParams.Height)应由控件中的相应属性设置,例如 Control.TextControl.WidthControl.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. 仅当包装标准 Windows 控件类或设置 Windows 窗体命名空间未提供的样式时,才应扩展 CreateParamsThe 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. 有关创建控件参数的详细信息,请参阅 CreateWindowCreateWindowEx 函数以及CREATESTRUCT结构文档。For more information about creating control parameters, see the CreateWindow and CreateWindowEx functions and the CREATESTRUCT structure documentation.

Notes to Inheritors

在派生类中重写 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.

Applies to

See also