ToolboxItem 생성자
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
ToolboxItem 클래스의 새 인스턴스를 초기화합니다.
오버로드
ToolboxItem() |
ToolboxItem 클래스의 새 인스턴스를 초기화합니다. |
ToolboxItem(Type) |
지정된 구성 요소 형식을 만드는 ToolboxItem 클래스의 새 인스턴스를 초기화합니다. |
예제
다음 코드 예제에서는 사용자 지정 도구 상자 항목 구현에 ToolboxItem 파생 된 클래스에서 ToolboxItem 생성자를 사용 하는 방법을 보여 줍니다. 이 코드 예제는에 대해 제공 된 큰 예제의 일부는 ToolboxItem 클래스입니다.
// Toolbox items must be serializable.
[Serializable]
class MyToolboxItem : ToolboxItem
{
// The add components dialog in Visual Studio looks for a public
// constructor that takes a type.
public MyToolboxItem(Type toolType)
: base(toolType)
{
}
// And you must provide this special constructor for serialization.
// If you add additional data to MyToolboxItem that you
// want to serialize, you may override Deserialize and
// Serialize methods to add that data.
MyToolboxItem(SerializationInfo info, StreamingContext context)
{
Deserialize(info, context);
}
// Let's override the creation code and pop up a dialog.
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 ToolboxItemDialog())
{
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;
}
}
}
}
<Serializable()> _
Class MyToolboxItem
Inherits ToolboxItem
' The add components dialog in Visual Studio looks for a public
' constructor that takes a type.
Public Sub New(ByVal toolType As Type)
MyBase.New(toolType)
End Sub
' And you must provide this special constructor for serialization.
' If you add additional data to MyToolboxItem that you
' want to serialize, you may override Deserialize and
' Serialize methods to add that data.
Sub New(ByVal info As SerializationInfo, _
ByVal context As StreamingContext)
Deserialize(info, context)
End Sub
' Let's override the creation code and pop up a dialog.
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
End Class
ToolboxItem()
ToolboxItem 클래스의 새 인스턴스를 초기화합니다.
public:
ToolboxItem();
public ToolboxItem ();
Public Sub New ()
예제
다음 코드 예제에서는 사용자 지정 도구 상자 항목 구현에 ToolboxItem 파생 된 클래스에서 ToolboxItem 생성자를 사용 하는 방법을 보여 줍니다. 이 코드 예제는에 대해 제공 된 큰 예제의 일부는 ToolboxItem 클래스입니다.
// Toolbox items must be serializable.
[Serializable]
class MyToolboxItem : ToolboxItem
{
// The add components dialog in Visual Studio looks for a public
// constructor that takes a type.
public MyToolboxItem(Type toolType)
: base(toolType)
{
}
// And you must provide this special constructor for serialization.
// If you add additional data to MyToolboxItem that you
// want to serialize, you may override Deserialize and
// Serialize methods to add that data.
MyToolboxItem(SerializationInfo info, StreamingContext context)
{
Deserialize(info, context);
}
// Let's override the creation code and pop up a dialog.
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 ToolboxItemDialog())
{
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;
}
}
}
}
<Serializable()> _
Class MyToolboxItem
Inherits ToolboxItem
' The add components dialog in Visual Studio looks for a public
' constructor that takes a type.
Public Sub New(ByVal toolType As Type)
MyBase.New(toolType)
End Sub
' And you must provide this special constructor for serialization.
' If you add additional data to MyToolboxItem that you
' want to serialize, you may override Deserialize and
' Serialize methods to add that data.
Sub New(ByVal info As SerializationInfo, _
ByVal context As StreamingContext)
Deserialize(info, context)
End Sub
' Let's override the creation code and pop up a dialog.
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
End Class
적용 대상
ToolboxItem(Type)
지정된 구성 요소 형식을 만드는 ToolboxItem 클래스의 새 인스턴스를 초기화합니다.
public:
ToolboxItem(Type ^ toolType);
public ToolboxItem (Type toolType);
public ToolboxItem (Type? toolType);
new System.Drawing.Design.ToolboxItem : Type -> System.Drawing.Design.ToolboxItem
Public Sub New (toolType As Type)
매개 변수
- toolType
- Type
도구 상자 항목에서 만드는 IComponent 형식입니다.
예외
예제
다음 코드 예제에서는 사용자 지정 도구 상자 항목 구현에 ToolboxItem 파생 된 클래스에서 ToolboxItem 생성자를 사용 하는 방법을 보여 줍니다. 이 코드 예제는에 대해 제공 된 큰 예제의 일부는 ToolboxItem 클래스입니다.
// Toolbox items must be serializable.
[Serializable]
class MyToolboxItem : ToolboxItem
{
// The add components dialog in Visual Studio looks for a public
// constructor that takes a type.
public MyToolboxItem(Type toolType)
: base(toolType)
{
}
// And you must provide this special constructor for serialization.
// If you add additional data to MyToolboxItem that you
// want to serialize, you may override Deserialize and
// Serialize methods to add that data.
MyToolboxItem(SerializationInfo info, StreamingContext context)
{
Deserialize(info, context);
}
// Let's override the creation code and pop up a dialog.
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 ToolboxItemDialog())
{
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;
}
}
}
}
<Serializable()> _
Class MyToolboxItem
Inherits ToolboxItem
' The add components dialog in Visual Studio looks for a public
' constructor that takes a type.
Public Sub New(ByVal toolType As Type)
MyBase.New(toolType)
End Sub
' And you must provide this special constructor for serialization.
' If you add additional data to MyToolboxItem that you
' want to serialize, you may override Deserialize and
' Serialize methods to add that data.
Sub New(ByVal info As SerializationInfo, _
ByVal context As StreamingContext)
Deserialize(info, context)
End Sub
' Let's override the creation code and pop up a dialog.
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
End Class
적용 대상
.NET