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

注解

不应重写并使用属性来调整派生控件的属性。CreateParamsThe CreateParams property should not be overridden and used to adjust the properties of your derived control. 属性CreateParams.CaptionCreateParams.Height Control.Text Control.Width例如、和)应由控件中的相应属性设置,例如、和Control.HeightCreateParams.WidthProperties 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 窗体命名空间未提供的样式时进行扩展。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. 有关创建控件参数的详细信息,请参阅CreateWindowCreateWindowEx函数和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

适用于

另请参阅