ToolboxItem.CreateComponentsCore 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
调用工具箱项时,创建组件或组件数组。
重载
| 名称 | 说明 |
|---|---|
| CreateComponentsCore(IDesignerHost) |
调用工具箱项时,创建组件或组件数组。 |
| CreateComponentsCore(IDesignerHost, IDictionary) |
调用工具箱项时,创建组件数组。 |
CreateComponentsCore(IDesignerHost)
- Source:
- ToolboxItem.cs
- Source:
- ToolboxItem.cs
- Source:
- ToolboxItem.cs
- Source:
- ToolboxItem.cs
- Source:
- ToolboxItem.cs
调用工具箱项时,创建组件或组件数组。
protected:
virtual cli::array <System::ComponentModel::IComponent ^> ^ CreateComponentsCore(System::ComponentModel::Design::IDesignerHost ^ host);
protected virtual System.ComponentModel.IComponent[] CreateComponentsCore(System.ComponentModel.Design.IDesignerHost host);
protected virtual System.ComponentModel.IComponent[]? CreateComponentsCore(System.ComponentModel.Design.IDesignerHost? host);
abstract member CreateComponentsCore : System.ComponentModel.Design.IDesignerHost -> System.ComponentModel.IComponent[]
override this.CreateComponentsCore : System.ComponentModel.Design.IDesignerHost -> System.ComponentModel.IComponent[]
Protected Overridable Function CreateComponentsCore (host As IDesignerHost) As IComponent()
参数
- host
- IDesignerHost
承载 IDesignerHost 工具箱项的项。
返回
已创建 IComponent 对象的数组。
注解
host否则null,该方法CreateComponentsCore会将新组件添加到设计器。
继承者说明
可以重写 CreateComponentsCore(IDesignerHost) 该方法以返回工具箱项创建的组件或组件。
另请参阅
适用于
CreateComponentsCore(IDesignerHost, IDictionary)
- Source:
- ToolboxItem.cs
- Source:
- ToolboxItem.cs
- Source:
- ToolboxItem.cs
- Source:
- ToolboxItem.cs
- Source:
- ToolboxItem.cs
调用工具箱项时,创建组件数组。
protected:
virtual cli::array <System::ComponentModel::IComponent ^> ^ CreateComponentsCore(System::ComponentModel::Design::IDesignerHost ^ host, System::Collections::IDictionary ^ defaultValues);
protected virtual System.ComponentModel.IComponent[] CreateComponentsCore(System.ComponentModel.Design.IDesignerHost host, System.Collections.IDictionary defaultValues);
protected virtual System.ComponentModel.IComponent[]? CreateComponentsCore(System.ComponentModel.Design.IDesignerHost? host, System.Collections.IDictionary? defaultValues);
abstract member CreateComponentsCore : System.ComponentModel.Design.IDesignerHost * System.Collections.IDictionary -> System.ComponentModel.IComponent[]
override this.CreateComponentsCore : System.ComponentModel.Design.IDesignerHost * System.Collections.IDictionary -> System.ComponentModel.IComponent[]
Protected Overridable Function CreateComponentsCore (host As IDesignerHost, defaultValues As IDictionary) As IComponent()
参数
- host
- IDesignerHost
创建组件时要使用的设计器主机。
- defaultValues
- IDictionary
用于初始化组件的默认值的属性名称/值对的字典。
返回
已创建 IComponent 对象的数组。
示例
下面的代码示例演示如何 CreateComponentsCore 在派生自 ToolboxItem 自定义工具箱项实现的类中使用该方法。 该代码示例是 ToolboxItem 类中的一个较大示例的一部分。
protected override IComponent[] CreateComponentsCore(
System.ComponentModel.Design.IDesignerHost host,
System.Collections.IDictionary defaultValues)
{
// Get the string we want to fill in the custom
// user control. If the user cancels out of the dialog,
// return null or an empty array to signify that the
// tool creation was canceled.
using (ToolboxItemDialog d = new())
{
if (d.ShowDialog() == DialogResult.OK)
{
string text = d.CreationText;
IComponent[] comps =
base.CreateComponentsCore(host, defaultValues);
// comps will have a single component: our data type.
((UserControl1)comps[0]).LabelText = text;
return comps;
}
else
{
return null;
}
}
}
Protected Overrides Function CreateComponentsCore( _
ByVal host As System.ComponentModel.Design.IDesignerHost, _
ByVal defaultValues As System.Collections.IDictionary) _
As IComponent()
' Get the string we want to fill in the custom
' user control. If the user cancels out of the dialog,
' return null or an empty array to signify that the
' tool creation was canceled.
Using d As New ToolboxItemDialog()
If d.ShowDialog() = DialogResult.OK Then
Dim [text] As String = d.CreationText
Dim comps As IComponent() = _
MyBase.CreateComponentsCore(host, defaultValues)
' comps will have a single component: our data type.
CType(comps(0), UserControl1).LabelText = [text]
Return comps
Else
Return Nothing
End If
End Using
End Function
注解
host否则null,该方法CreateComponentsCore会将新组件添加到设计器。