Version

CreateToolInstance Method

Creates and returns an instance of the tool identified by the specified GUID id.
Syntax
'Declaration
 
Function CreateToolInstance( _
   ByVal toolID As Guid, _
   ByVal key As String _
) As ToolBase
ToolBase CreateToolInstance( 
   Guid toolID,
   string key
)

Parameters

toolID
A unique id which corresponds to the tool type which must be created.
key
The key to give the new tool.
Example
The following sample code illustrates how to register custom tool types for use in the designer. For a complete example refer to the 'ToolProvider Component' sample project.

Imports System
Imports System.Windows.Forms
Imports Infragistics.Win.UltraWinToolbars

Namespace ToolProvider

#Region "ToolProviderAsManager class (derived from UltraToolbarsManager)"

    ' This class demonstrates how to write a custom tool provider that derives from UltraToolbarsManager.
    ' See the notes above for more information on the options available when creating custom tool providers.
    ' 
    ' The ToolProviderAsManager class performs 2 important functions:
    '		1. Registering the custom tool types that it supports (see the private ToolFactory class's constructor)
    '			When registering a custom tool type, the tool provider:
    '				a. supplies a reference to an IToolProvider implementation
    '				b. supplies a Guid to identify the custom tool type.  This Guid will be contained in the
    '				   customizer's request to create an instance of the custom tool type.
    '				c. supplies a descriptive string used in the NewTool dialog to identify the custom tool
    '				d. supplies a string to be used as the basis for the custom tool instance's key and caption
    '			
    '		2. Contains a private ToolFactory class that implements the IToolProvider interface which allows the
    '		   Customizer to call back when it needs to create an instance of a registered custom tool.
    '		   
    '	The ToolProviderAsManager also overrides the virtual property ShowBuiltInToolTypesInCustomizer to 
    '	demonstrate how to prevent toolbars manager from displaying the built-in tools in the designtime
    '	customizer.
    Public Class ToolProviderAsManager
        Inherits UltraToolbarsManager

#Region "Member Variables"

        ' A static reference to our private tool provider class.  An instance of this class is
        ' created in our static constructor.
        Private Shared m_toolFactory As ToolProviderAsManager.ToolFactory = Nothing

#End Region   'Member Variables

#Region "Constructor"

        '/ <summary>
        '/ Static constructor used to create a single instance of our private tool provider class.
        '/ </summary>
        Shared Sub New()
            ToolProviderAsManager.m_toolFactory = New ToolProviderAsManager.ToolFactory()
        End Sub

        '/ <summary>
        '/ Standard constructor.
        '/ </summary>
        Public Sub New()
        End Sub

#End Region   'Constructor

#Region "Constants"

        Friend Shared ReadOnly CUSTOMBUTTON2_TOOLID As Guid = New Guid("66227453-9991-1019-ABC4-872BCDEF5413")
        Friend Shared ReadOnly CUSTOMCOMBOBOX2_TOOLID As Guid = New Guid("66227453-9991-1019-ABC4-872BCDEF5414")

#End Region   'Constants

#Region "Base Class Overrides"

#Region "ShowBuiltInToolTypesInCustomizer"

        Protected Overrides ReadOnly Property ShowBuiltInToolTypesInCustomizer() As Boolean
            Get
                ' Comment-out the following line and uncomment the subsequent line to prevent the
                ' toolbars manager's built-in tooltypes from being displayed in the runtime customizer.
                Return True
                'return false;
            End Get
        End Property

#End Region    'ShowBuiltInToolTypesInCustomizer

#End Region   'Base Class Overrides

#Region "Private Class ToolFactory"

        '/ <summary>
        '/ A private class that implements IToolProvider.
        '/ </summary>
        Private Class ToolFactory
            Implements IToolProvider
#Region "Constructor"

            Friend Sub New()
                Dim result As Boolean

                ' Register some custom tool types with UltraToolbarsManager.
                Try
                    ' CustomButtonTool class.
                    result = UltraToolbarsManager.RegisterCustomToolType(Me, ToolProviderAsManager.CUSTOMBUTTON2_TOOLID, "Custom Button", "CustomButtonTool")
                    If result = False Then
                        MessageBox.Show("Error registering CustomButtonTool class!")
                    End If


                    ' CustomComboBoxTool class.
                    result = UltraToolbarsManager.RegisterCustomToolType(Me, ToolProviderAsManager.CUSTOMCOMBOBOX2_TOOLID, "Custom ComboBox", "CustomComboBoxTool")
                    If result = False Then
                        MessageBox.Show("Error registering CustomComboBoxTool class!")
                    End If
                Catch
                    MessageBox.Show("Error registering custom tool classes!")
                End Try
            End Sub

#End Region    'Constructor

#Region "CreateToolInstance"

            '/ <summary>
            '/ Creates and returns an instance of the tool identified by the specified GUID id.
            '/ </summary>
            '/ <param name="toolID">The Guid identifier specified for the tool when it was registered.</param>
            '/ <param name="key">The key assigned to the tool.</param>
            '/ <returns>A new instance of the specified tool.</returns>
            Function CreateToolInstance(ByVal toolID As Guid, ByVal key As String) As ToolBase Implements IToolProvider.CreateToolInstance
                If toolID.Equals(ToolProviderAsManager.CUSTOMBUTTON2_TOOLID) Then
                    Return New CustomButtonTool(key)
                End If

                If toolID.Equals(ToolProviderAsManager.CUSTOMCOMBOBOX2_TOOLID) Then
                    Return New CustomComboBoxTool(key)
                End If


                ' The tool ID is unknown to us so return null.
                Return Nothing
            End Function

#End Region     'CreateToolInstance
        End Class

#End Region   'Private Class ToolFactory
    End Class

#End Region 'ToolProviderAsManager class (derived from UltraToolbarsManager)

End Namespace
using System;
using System.Windows.Forms;

using Infragistics.Win.UltraWinToolbars;

namespace ToolProvider
{
	#region ToolProviderAsManager class (derived from UltraToolbarsManager)

	/// <summary>
	/// This class demonstrates how to write a custom tool provider that derives from UltraToolbarsManager.
	/// See the notes above for more information on the options available when creating custom tool providers.
	/// 
	/// The ToolProviderAsManager class performs 2 important functions:
	///		1. Registering the custom tool types that it supports (see the private ToolFactory class's constructor)
	///			When registering a custom tool type, the tool provider:
	///				a. supplies a reference to an IToolProvider implementation
	///				b. supplies a Guid to identify the custom tool type.  This Guid will be contained in the
	///				   customizer's request to create an instance of the custom tool type.
	///				c. supplies a descriptive string used in the NewTool dialog to identify the custom tool
	///				d. supplies a string to be used as the basis for the custom tool instance's key and caption
	///			
	///		2. Contains a private ToolFactory class that implements the IToolProvider interface which allows the
	///		   Customizer to call back when it needs to create an instance of a registered custom tool.
	///		   
	///	The ToolProviderAsManager also overrides the virtual property ShowBuiltInToolTypesInCustomizer to 
	///	demonstrate how to prevent toolbars manager from displaying the built-in tools in the designtime
	///	customizer.
	/// </summary>
	public class ToolProviderAsManager : UltraToolbarsManager
	{
		#region Member Variables

		// A static reference to our private tool provider class.  An instance of this class is
		// created in our static constructor.
		private static ToolProviderAsManager.ToolFactory		toolFactory = null;

		#endregion Member Variables

		#region Constructor

		/// <summary>
		/// Static constructor used to create a single instance of our private tool provider class.
		/// </summary>
		static ToolProviderAsManager()
		{
			ToolProviderAsManager.toolFactory = new ToolProviderAsManager.ToolFactory();
		}

		/// <summary>
		/// Standard constructor.
		/// </summary>
		public ToolProviderAsManager()
		{
		}

		#endregion Constructor

		#region Constants

		internal static readonly Guid		CUSTOMBUTTON2_TOOLID			= new Guid("66227453-9991-1019-ABC4-872BCDEF5413");
		internal static readonly Guid		CUSTOMCOMBOBOX2_TOOLID			= new Guid("66227453-9991-1019-ABC4-872BCDEF5414");

		#endregion Constants

		#region Base Class Overrides

			#region ShowBuiltInToolTypesInCustomizer
	
		protected override bool ShowBuiltInToolTypesInCustomizer
		{
			get
			{
				// Comment-out the following line and uncomment the subsequent line to prevent the
				// toolbars manager's built-in tooltypes from being displayed in the runtime customizer.
				return true;
				//return false;
			}
		}

			#endregion ShowBuiltInToolTypesInCustomizer

		#endregion Base Class Overrides

		#region Private Class ToolFactory

		/// <summary>
		/// A private class that implements IToolProvider.
		/// </summary>
		private class ToolFactory : IToolProvider
		{
			#region Constructor

			internal ToolFactory()
			{
				bool result;

				// Register some custom tool types with UltraToolbarsManager.
				try
				{
					// CustomButtonTool class.
					result = UltraToolbarsManager.RegisterCustomToolType(this, ToolProviderAsManager.CUSTOMBUTTON2_TOOLID, "Custom Button", "CustomButtonTool");
					if (result == false)
						MessageBox.Show("Error registering CustomButtonTool class!");


					// CustomComboBoxTool class.
					result = UltraToolbarsManager.RegisterCustomToolType(this, ToolProviderAsManager.CUSTOMCOMBOBOX2_TOOLID, "Custom ComboBox", "CustomComboBoxTool");
					if (result == false)
						MessageBox.Show("Error registering CustomComboBoxTool class!");
				}
				catch
				{
					MessageBox.Show("Error registering custom tool classes!");
				}
			}

			#endregion Constructor

			#region CreateToolInstance

			/// <summary>
			/// Creates and returns an instance of the tool identified by the specified GUID id.
			/// </summary>
			/// <param name="toolID">The Guid identifier specified for the tool when it was registered.</param>
			/// <param name="key">The key assigned to the tool.</param>
			/// <returns>A new instance of the specified tool.</returns>
			ToolBase IToolProvider.CreateToolInstance(Guid toolID, string key)
			{
				if (toolID == ToolProviderAsManager.CUSTOMBUTTON2_TOOLID)
					return new CustomButtonTool(key);

				if (toolID == ToolProviderAsManager.CUSTOMCOMBOBOX2_TOOLID)
					return new CustomComboBoxTool(key);


				// The tool ID is unknown to us so return null.
				return null;
			}

				#endregion CreateToolInstance
		}

		#endregion Private Class ToolFactory
	}

	#endregion ToolProviderAsManager class (derived from UltraToolbarsManager)
}
Requirements

Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also