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.HeightCreateParams.WidthCreateParams.Caption属性应由控件中的相应属性(如 、 Control.WidthControl.HeightControl.Text设置。 CreateParams仅当包装标准 Windows 控件类或设置Windows 窗体命名空间未提供的样式时,才应扩展 。 有关创建控件参数的详细信息,请参阅 CreateWindowCreateWindowEx 函数和 CREATESTRUCT 结构文档。

继承者说明

重写派生类中的 CreateParams 属性时,使用基类的 CreateParams 属性扩展基实现。 否则,必须提供所有实现。

适用于

另请参阅