ToolboxItem コンストラクタとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > ToolboxItem コンストラクタの意味・解説 

ToolboxItem コンストラクタ (Type)

指定した型のコンポーネント作成する ToolboxItem クラス新しインスタンス初期化します。

名前空間: System.Drawing.Design
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public Sub New ( _
    toolType As Type _
)
Dim toolType As Type

Dim instance As New ToolboxItem(toolType)
public ToolboxItem (
    Type toolType
)
public:
ToolboxItem (
    Type^ toolType
)
public ToolboxItem (
    Type toolType
)
public function ToolboxItem (
    toolType : Type
)

パラメータ

toolType

ツールボックス項目が作成する IComponent の型。

例外例外
例外種類条件

InvalidOperationException

ToolboxItemロックされています。

使用例使用例

ToolboxItem から派生したクラスToolboxItem コンストラクタ使用してカスタム ツールボックス項目を実装するコード例次に示します。このコード例は、ToolboxItem クラストピック取り上げているコード例一部分です。

<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.
        Dim 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 Function
End Class
// 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.
        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;
        }
    }
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ToolboxItem クラス
ToolboxItem メンバ
System.Drawing.Design 名前空間

ToolboxItem コンストラクタ

ToolboxItem クラス新しインスタンス初期化します。
オーバーロードの一覧オーバーロードの一覧

参照参照

関連項目

ToolboxItem クラス
ToolboxItem メンバ
System.Drawing.Design 名前空間

ToolboxItem コンストラクタ ()

ToolboxItem クラス新しインスタンス初期化します。

名前空間: System.Drawing.Design
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

public ToolboxItem ()
public:
ToolboxItem ()
public ToolboxItem ()
使用例使用例

ToolboxItem から派生したクラスToolboxItem コンストラクタ使用してカスタム ツールボックス項目を実装するコード例次に示します。このコード例は、ToolboxItem クラストピック取り上げているコード例一部分です。

<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.
        Dim 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 Function
End Class
// 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.
        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;
        }
    }
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ToolboxItem クラス
ToolboxItem メンバ
System.Drawing.Design 名前空間



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「ToolboxItem コンストラクタ」の関連用語

ToolboxItem コンストラクタのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ToolboxItem コンストラクタのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS