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. 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
{
    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.CaptionCreateParams.Width,并CreateParams.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. 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

适用于

另请参阅