ToolboxItemCreatorCallback デリゲートとは? わかりやすく解説

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

ToolboxItemCreatorCallback デリゲート

ToolboxItemCreatorCallback イベント処理するメソッド表します

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

Public Delegate Function
 ToolboxItemCreatorCallback ( _
    serializedObject As Object, _
    format As String _
) As ToolboxItem
Dim instance As New ToolboxItemCreatorCallback(AddressOf
 HandlerMethod)
public delegate ToolboxItem ToolboxItemCreatorCallback (
    Object serializedObject,
    string format
)
public delegate ToolboxItem^ ToolboxItemCreatorCallback (
    Object^ serializedObject, 
    String^ format
)
/** @delegate */
public delegate ToolboxItem ToolboxItemCreatorCallback (
    Object serializedObject, 
    String format
)
JScript では、デリゲート使用できますが、新規に宣言することはできません。

パラメータ

serializedObject

ToolboxItem を作成するデータを含むオブジェクト

format

戻り値
serializedObject指定された逆シリアル化 ToolboxItem オブジェクト

解説解説
使用例使用例

IToolboxService使用してツールボックスに、"Text" データ形式ハンドラ追加したり、ToolboxItemCreatorCallback実行したりするコンポーネント提供する方法次の例に示しますデータ クリエータコールバック デリゲートは、テキスト データ渡してツールボックス貼り付けテキスト格納する TextBox作成するカスタム ToolboxItemフォームにそのテキスト データドラッグます。

Imports System
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Drawing
Imports System.Drawing.Design
Imports System.Windows.Forms

' Component that adds a "Text" data format ToolboxItemCreatorCallback
 
' to the Toolbox that creates a custom ToolboxItem that 
' creates a TextBox containing the text data.
<System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand,
 Name:="FullTrust")> _
Public Class TextDataTextBoxComponent
    Inherits System.ComponentModel.Component

    Private creatorAdded As Boolean
 = False
    Private ts As IToolboxService

    Public Sub New()
    End Sub

    ' ISite override to register TextBox creator
    Public Overrides Property
 Site() As System.ComponentModel.ISite
        Get
            Return MyBase.Site
        End Get
        Set(ByVal Value As
 System.ComponentModel.ISite)
            If Not (Value Is
 Nothing) Then
                MyBase.Site = Value
                If Not creatorAdded Then
                    AddTextTextBoxCreator()
                End If
            Else
                If creatorAdded Then
                    RemoveTextTextBoxCreator()
                End If
                MyBase.Site = Value
            End If
        End Set
    End Property

    ' Adds a "Text" data format creator to the toolbox that
 creates 
    ' a textbox from a text fragment pasted to the toolbox.
    Private Sub AddTextTextBoxCreator()
        ts = CType(GetService(GetType(IToolboxService)), IToolboxService)
        If Not (ts Is Nothing)
 Then
            Dim textCreator As New
 ToolboxItemCreatorCallback(AddressOf Me.CreateTextBoxForText)
            Try
                ts.AddCreator(textCreator, "Text",
 CType(GetService(GetType(IDesignerHost)), IDesignerHost))
                creatorAdded = True
            Catch ex As Exception
                MessageBox.Show(ex.ToString(), "Exception Information")
            End Try
        End If
    End Sub

    ' Removes any "Text" data format creator from the toolbox.
    Private Sub RemoveTextTextBoxCreator()
        If Not (ts Is Nothing)
 Then
            ts.RemoveCreator("Text", CType(GetService(GetType(IDesignerHost)),
 IDesignerHost))
            creatorAdded = False
        End If
    End Sub

    ' ToolboxItemCreatorCallback delegate format method to create 
    ' the toolbox item.
    Private Function CreateTextBoxForText(ByVal
 serializedObject As Object, ByVal
 format As String) As ToolboxItem
        Dim formats As String()
 = CType(serializedObject, System.Windows.Forms.DataObject).GetFormats()
        If CType(serializedObject, System.Windows.Forms.DataObject).GetDataPresent("System.String",
 True) Then
            Return New TextToolboxItem(CStr(CType(serializedObject,
 System.Windows.Forms.DataObject).GetData("System.String",
 True)))
        End If
        Return Nothing
    End Function

    Protected Overloads Overrides
 Sub Dispose(ByVal disposing As
 Boolean)
        If creatorAdded Then
            RemoveTextTextBoxCreator()
        End If
    End Sub

End Class

' Custom toolbox item creates a TextBox and sets its Text property
' to the constructor-specified text.
<System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand,
 Name:="FullTrust")> _
Public Class TextToolboxItem
    Inherits System.Drawing.Design.ToolboxItem

    Private [text] As String

    Delegate Sub SetTextMethodHandler(ByVal
 c As Control, ByVal [text] As
 String)

    Public Sub New(ByVal
 [text] As String)
        Me.text = [text]
    End Sub

    ' ToolboxItem.CreateComponentsCore override to create the TextBox
 
    ' and link a method to set its Text property.
    <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand,
 Name:="FullTrust")> _
    Protected Overrides Function
 CreateComponentsCore(ByVal host As System.ComponentModel.Design.IDesignerHost)
 As System.ComponentModel.IComponent()
        Dim textbox As System.Windows.Forms.TextBox
 = CType(host.CreateComponent(GetType(TextBox)), TextBox)

        ' Because the designer resets the text of the textbox, use 
        ' a SetTextMethodHandler to set the text to the value of 
        ' the text data.
        Dim c As Control = host.RootComponent

        c.BeginInvoke(New SetTextMethodHandler(AddressOf
 OnSetText), New Object() {textbox, [text]})

        Return New System.ComponentModel.IComponent()
 {textbox}
    End Function

    ' Method to set the text property of a TextBox after it is initialized.
    Private Sub OnSetText(ByVal
 c As Control, ByVal [text] As
 String)
        c.Text = [text]
    End Sub

End Class
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Drawing.Design;
using System.Windows.Forms;

namespace TextDataTextBoxComponent
{
    // Component that adds a "Text" data format ToolboxItemCreatorCallback
 
    // to the Toolbox that creates a custom ToolboxItem that 
    // creates a TextBox containing the text data.
    [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand,
 Name = "FullTrust")]
    public class TextDataTextBoxComponent :
 System.ComponentModel.Component
    {
        private bool creatorAdded = false;
        private IToolboxService ts;

        public TextDataTextBoxComponent()
        {                     
        }

        // ISite override to register TextBox creator
        public override System.ComponentModel.ISite Site
        {
            get
            {
                return base.Site;
            }
            set
            {
                if( value != null )
                {                    
                    base.Site = value;
                    if( !creatorAdded )
                        AddTextTextBoxCreator();                    
                }
                else
                {
                    if( creatorAdded )
                        RemoveTextTextBoxCreator();
                    base.Site = value;             
                }
            }
        }

        // Adds a "Text" data format creator to the toolbox
 that creates 
        // a textbox from a text fragment pasted to the toolbox.
        private void AddTextTextBoxCreator()
        {
            ts = (IToolboxService)GetService(typeof(IToolboxService));
            if (ts != null) 
            {
                ToolboxItemCreatorCallback textCreator = new ToolboxItemCreatorCallback(this.CreateTextBoxForText);
                try
                {
                    ts.AddCreator(textCreator, "Text", (IDesignerHost)GetService(typeof(IDesignerHost)));
                    creatorAdded = true;
                }
                catch(Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "Exception Information");
                }                
            }
        }

        // Removes any "Text" data format creator from the
 toolbox.
        private void RemoveTextTextBoxCreator()
        {
            if (ts != null)             
            {
                ts.RemoveCreator("Text", (IDesignerHost)GetService(typeof(IDesignerHost)));
            
                creatorAdded = false;
            }
        }

        // ToolboxItemCreatorCallback delegate format method to create
 
        // the toolbox item.
        private ToolboxItem CreateTextBoxForText(object serializedObject,
 string format)
        {
            string[] formats = ((System.Windows.Forms.DataObject)serializedObject).GetFormats();
            if( ((System.Windows.Forms.DataObject)serializedObject).GetDataPresent("System.String",
 true) )           
                return new TextToolboxItem(
 (string)((System.Windows.Forms.DataObject)serializedObject).GetData("System.String",
 true) );            
            return null;
        }

        protected override void Dispose(bool
 disposing)
        {
            if( creatorAdded )
                RemoveTextTextBoxCreator();
        }        
    }

    // Custom toolbox item creates a TextBox and sets its Text property
    // to the constructor-specified text.
    [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand,
 Name = "FullTrust")] 
    public class TextToolboxItem : System.Drawing.Design.ToolboxItem
    {
        private string text;
        private delegate void SetTextMethodHandler(Control
 c, string text);

        public TextToolboxItem(string text)
 : base()
        {
            this.text = text;
        }

        // ToolboxItem.CreateComponentsCore override to create the TextBox
 
        // and link a method to set its Text property.
        [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand,
 Name="FullTrust")] 
        protected override System.ComponentModel.IComponent[]
 CreateComponentsCore(System.ComponentModel.Design.IDesignerHost host)
        {
            System.Windows.Forms.TextBox textbox = (TextBox)host.CreateComponent(typeof(TextBox));
                
            // Because the designer resets the text of the textbox,
 use 
            // a SetTextMethodHandler to set the text to the value of
 
            // the text data.
            Control c = host.RootComponent as Control;
            c.BeginInvoke(new SetTextMethodHandler(OnSetText),
 new object[] {textbox, text});
           
            return new System.ComponentModel.IComponent[]
 { textbox };
        }        

        // Method to set the text property of a TextBox after it is
 initialized.
        private void OnSetText(Control c, string
 text) 
        {
            c.Text = text;
        }
    }
}
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>
#using <System.dll>

using namespace System;
using namespace System::ComponentModel;
using namespace System::ComponentModel::Design;
using namespace System::Drawing;
using namespace System::Drawing::Design;
using namespace System::Windows::Forms;
using namespace System::Security::Permissions;

namespace TextDataTextBoxComponent
{
   // Custom toolbox item creates a TextBox and sets its Text property
   // to the constructor-specified text.
   [PermissionSetAttribute(SecurityAction::Demand, Name="FullTrust")]
   public ref class TextToolboxItem: public
 System::Drawing::Design::ToolboxItem
   {
   private:
      String^ text;
      delegate void SetTextMethodHandler( Control^ c, String^
 text );

   public:
      TextToolboxItem( String^ text )
         : ToolboxItem()
      {
         this->text = text;
      }

   protected:

      // ToolboxItem::CreateComponentsCore  to create the TextBox
      // and link a method to set its Text property.

      virtual array<System::ComponentModel::IComponent^>^ CreateComponentsCore(
 System::ComponentModel::Design::IDesignerHost^ host ) override
      {
         System::Windows::Forms::TextBox^ textbox = dynamic_cast<TextBox^>(host->CreateComponent(
 TextBox::typeid ));
         
         // Because the designer resets the text of the textbox, use
         // a SetTextMethodHandler to set the text to the value of
         // the text data.
         Control^ c = dynamic_cast<Control^>(host->RootComponent);
         array<Object^>^temp0 = {textbox,text};
         c->BeginInvoke( gcnew SetTextMethodHandler( this,
 &TextToolboxItem::OnSetText ), temp0 );
         array<System::ComponentModel::IComponent^>^temp1 = {textbox};
         return temp1;
      }

   private:

      // Method to set the text property of a TextBox after it is initialized.
      void OnSetText( Control^ c, String^ text )
      {
         c->Text = text;
      }

   };


   // Component that adds a "Text" data format ToolboxItemCreatorCallback
   // to the Toolbox that creates a custom ToolboxItem that
   // creates a TextBox containing the text data.
   public ref class TextDataTextBoxComponent:
 public System::ComponentModel::Component
   {
   private:
      bool creatorAdded;
      IToolboxService^ ts;

   public:
      TextDataTextBoxComponent()
      {
         creatorAdded = false;
      }


      property System::ComponentModel::ISite^ Site 
      {
         // ISite to register TextBox creator
         virtual System::ComponentModel::ISite^ get() override
         {
            return __super::Site;
         }

         virtual void set( System::ComponentModel::ISite^
 value ) override
         {
            if ( value != nullptr )
            {
               __super::Site = value;
               if (  !creatorAdded )
                              AddTextTextBoxCreator();
            }
            else
            {
               if ( creatorAdded )
                              RemoveTextTextBoxCreator();
               __super::Site = value;
            }
         }
      }

   private:

      // Adds a "Text" data format creator to the toolbox
 that creates
      // a textbox from a text fragment pasted to the toolbox.
      void AddTextTextBoxCreator()
      {
         ts = dynamic_cast<IToolboxService^>(GetService( IToolboxService::typeid
 ));
         if ( ts != nullptr )
         {
            ToolboxItemCreatorCallback^ textCreator = gcnew ToolboxItemCreatorCallback(
 this, &TextDataTextBoxComponent::CreateTextBoxForText );
            try
            {
               ts->AddCreator( textCreator, "Text", dynamic_cast<IDesignerHost^>(GetService(
 IDesignerHost::typeid )) );
               creatorAdded = true;
            }
            catch ( Exception^ ex ) 
            {
               MessageBox::Show( ex->ToString(), "Exception Information"
 );
            }
         }
      }


      // Removes any "Text" data format creator from the toolbox.
      void RemoveTextTextBoxCreator()
      {
         if ( ts != nullptr )
         {
            ts->RemoveCreator( "Text", dynamic_cast<IDesignerHost^>(GetService(
 IDesignerHost::typeid )) );
            creatorAdded = false;
         }
      }


      // ToolboxItemCreatorCallback delegate format method to create
      // the toolbox item.
      ToolboxItem^ CreateTextBoxForText( Object^ serializedObject, String^ format
 )
      {
         array<String^>^formats = (dynamic_cast<System::Windows::Forms::DataObject^>(serializedObject))->GetFormats();
         if ( (dynamic_cast<System::Windows::Forms::DataObject^>(serializedObject))->GetDataPresent(
 "System::String", true ) )
                  return gcnew TextToolboxItem( dynamic_cast<String^>((dynamic_cast<System::Windows::Forms::DataObject^>(serializedObject))->GetData(
 "System::String", true )) );

         return nullptr;
      }

   public:
      ~TextDataTextBoxComponent()
      {
         if ( creatorAdded )
                  RemoveTextTextBoxCreator();
      }
   };
}
package TextDataTextBoxComponent;

import System.*;
import System.ComponentModel.*;
import System.ComponentModel.Design.*;
import System.Drawing.*;
import System.Drawing.Design.*;
import System.Windows.Forms.*;
// Component that adds a "Text" data format ToolboxItemCreatorCallback
 
// to the Toolbox that creates a custom ToolboxItem that 
// creates a TextBox containing the text data.
public class TextDataTextBoxComponent extends
 System.ComponentModel.Component
{
    private boolean creatorAdded = false;
    private IToolboxService ts;

    public TextDataTextBoxComponent()
    {
    } //TextDataTextBoxComponent

    // ISite override to register TextBox creator
    /** @property 
     */
    public System.ComponentModel.ISite get_Site()
    {
        return super.get_Site();
    } //get_Site

    /** @property 
     */
    public void set_Site(System.ComponentModel.ISite
 value)
    {
        if (value != null) {
            super.set_Site(value);
            if (!(creatorAdded)) {
                AddTextTextBoxCreator();
            }
        }
        else {
            if (creatorAdded) {
                RemoveTextTextBoxCreator();
            }
            super.set_Site(value);
        }
    } //set_Site

    // Adds a "Text" data format creator to the toolbox that
 creates 
    // a textbox from a text fragment pasted to the toolbox.
    private void AddTextTextBoxCreator()
    {
        ts = (IToolboxService)GetService(IToolboxService.class.ToType());
        if (ts != null) {
            ToolboxItemCreatorCallback textCreator =
                new ToolboxItemCreatorCallback(this.CreateTextBoxForText);
            try {
                ts.AddCreator(textCreator, "Text",
                    (IDesignerHost)GetService(IDesignerHost.class.ToType()));
                creatorAdded = true;
            }
            catch (System.Exception ex) {
                MessageBox.Show(ex.ToString(), "Exception Information");
            }
        }
    } //AddTextTextBoxCreator

    // Removes any "Text" data format creator from the toolbox.
    private void RemoveTextTextBoxCreator()
    {
        if (ts != null) {
            ts.RemoveCreator("Text",
                (IDesignerHost)GetService(IDesignerHost.class.ToType()));
            creatorAdded = false;
        }
    } //RemoveTextTextBoxCreator

    // ToolboxItemCreatorCallback delegate format method to create 
    // the toolbox item.
    private ToolboxItem CreateTextBoxForText(Object serializedObject
,
        String format)
    {
        String formats[] = 
            ((System.Windows.Forms.DataObject)serializedObject).GetFormats();
        if (((System.Windows.Forms.DataObject)serializedObject).
            GetDataPresent("System.String", true)) {
            return new TextToolboxItem((String)
                (((System.Windows.Forms.DataObject)serializedObject).
                GetData("System.String", true)));
        }
        return null;
    } //CreateTextBoxForText

    protected void Dispose(boolean disposing)
    {
        if (creatorAdded) {
            RemoveTextTextBoxCreator();
        }
    } //Dispose
} //TextDataTextBoxComponent

// Custom toolbox item creates a TextBox and sets its Text property
// to the constructor-specified text.
public class TextToolboxItem extends System.Drawing.Design.ToolboxItem
{
    private String text;

    /** @delegate 
     */
    private delegate void SetTextMethodHandler(Control
 c, String text);

    /** @attribute System.Security.Permissions.PermissionSet(
        System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")
     */
    public TextToolboxItem(String text)
    {
        this.text = text;
    } //TextToolboxItem

    // ToolboxItem.CreateComponentsCore override to create the TextBox
 
    // and link a method to set its Text property.
    /** @attribute System.Security.Permissions.PermissionSet(
        System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")
     */
    protected System.ComponentModel.IComponent[] CreateComponentsCore(
        System.ComponentModel.Design.IDesignerHost host)
    {
        System.Windows.Forms.TextBox textbox =
            (TextBox)host.CreateComponent(TextBox.class.ToType());
        // Because the designer resets the text of the textbox, use
 
        // a SetTextMethodHandler to set the text to the value of 
        // the text data.
        Control c = (Control)host.get_RootComponent();
        c.BeginInvoke(new SetTextMethodHandler(OnSetText),
            new Object[] { textbox, text });

        return new System.ComponentModel.IComponent[]
 { textbox };
    } //CreateComponentsCore

    // Method to set the text property of a TextBox after it is initialized.
    private void OnSetText(Control c, String
 text)
    {
        c.set_Text(text);
    } //OnSetText
} //TextToolboxItem
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
System.Drawing.Design 名前空間



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

辞書ショートカット

すべての辞書の索引

「ToolboxItemCreatorCallback デリゲート」の関連用語

ToolboxItemCreatorCallback デリゲートのお隣キーワード
検索ランキング

   

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



ToolboxItemCreatorCallback デリゲートのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS