ActivityToolboxItem.CreateComponentsCore(IDesignerHost) 方法

定义

在调用工具箱项时,创建 Activity 组件或 Activity 组件的数组。Creates an Activity component or an array of Activity components when the toolbox item is invoked.

protected:
 override cli::array <System::ComponentModel::IComponent ^> ^ CreateComponentsCore(System::ComponentModel::Design::IDesignerHost ^ host);
protected override System.ComponentModel.IComponent[] CreateComponentsCore (System.ComponentModel.Design.IDesignerHost host);
override this.CreateComponentsCore : System.ComponentModel.Design.IDesignerHost -> System.ComponentModel.IComponent[]
Protected Overrides Function CreateComponentsCore (host As IDesignerHost) As IComponent()

参数

host
IDesignerHost

要承载工具箱项的 IDesignerHostThe IDesignerHost to host the toolbox item.

返回

IComponent[]

创建的 IComponent 对象数组。An array of created IComponent objects.

示例

下面的示例演示了自定义活动的完整的 ActivityToolboxItem 类。The following example shows a complete ActivityToolboxItem class for a custom activity. 在本示例中,将重写 CreateComponentsCore 方法以便在 ParallelActivity 中插入两个自定义活动。In this example, the CreateComponentsCore method is overridden in order to insert 2 custom activities within a ParallelActivity.

[Serializable]
internal sealed class CustomActivityToolboxItem : ActivityToolboxItem
{
    public CustomActivityToolboxItem(Type type)
        : base(type)
    {
    }

    private CustomActivityToolboxItem(SerializationInfo info, StreamingContext context)
    {
        Deserialize(info, context);
    }

    protected override IComponent[] CreateComponentsCore(IDesignerHost designerHost)
    {
        CompositeActivity parallel = new ParallelActivity();
        parallel.Activities.Add(new CustomActivity());
        parallel.Activities.Add(new CustomActivity());

        return new IComponent[] { parallel };
    }
}
<Serializable()> _
Friend Class CustomActivityToolboxItem
    Inherits ActivityToolboxItem

    Public Sub New(ByVal type As Type)
        MyBase.new(type)
    End Sub

    Private Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext)
        Deserialize(info, context)
    End Sub

    Protected Overrides Function CreateComponentsCore(ByVal designerHost As IDesignerHost) As IComponent()
        Dim parallel As New ParallelActivity()
        parallel.Activities.Add(New CustomActivity())
        parallel.Activities.Add(New CustomActivity())

        Return New IComponent() {parallel}
    End Function
End Class

注解

CreateComponentsCore 方法返回 ActivityToolboxItem 所创建的组件。The CreateComponentsCore method returns the component or components that the ActivityToolboxItem creates.

适用于