|
class ToolBoxService : System.Drawing.Design.IToolboxService
{
// ToolBox
ListBox toolBox = null;
// View of host
Control view = null;
// Define the toolbox
public ListBox ToolBox { set { toolBox = value; } }
// Define the view of host
public Control View { set { view = value; } }
// Not use
public void AddCreator(System.Drawing.Design.ToolboxItemCreatorCallback creator,
string format, System.ComponentModel.Design.IDesignerHost host)
{
}
// Not use
public void AddCreator(System.Drawing.Design.ToolboxItemCreatorCallback creator,
string format)
{
}
// Not use
public void AddLinkedToolboxItem(System.Drawing.Design.ToolboxItem toolboxItem,
string category, System.ComponentModel.Design.IDesignerHost host)
{
}
// Not use
public void AddLinkedToolboxItem(System.Drawing.Design.ToolboxItem toolboxItem, System.ComponentModel.Design.IDesignerHost host)
{
}
// Add a ToolboxItem at the toolBox
public void AddToolboxItem(System.Drawing.Design.ToolboxItem toolboxItem,
string category)
{
AddToolboxItem(toolboxItem);
}
// Add a ToolboxItem at the toolBox
public void AddToolboxItem(System.Drawing.Design.ToolboxItem toolboxItem)
{
toolBox.Items.Add(toolboxItem);
}
// Not use
public System.Drawing.Design.CategoryNameCollection CategoryNames
{
get { return null; }
}
// Deserialize a toolboxitem necessary for the drag and drop
public System.Drawing.Design.ToolboxItem DeserializeToolboxItem(
object serializedObject, System.ComponentModel.Design.IDesignerHost host)
{
return DeserializeToolboxItem(serializedObject);
}
// Deserialize a toolboxitem necessary for the drag and drop
public System.Drawing.Design.ToolboxItem DeserializeToolboxItem(object serializedObject)
{
IDataObject dataObject = serializedObject as IDataObject;
if (dataObject == null)
{
return null;
}
System.Drawing.Design.ToolboxItem t = (System.Drawing.Design.ToolboxItem)
dataObject.GetData(typeof(System.Drawing.Design.ToolboxItem));
return t;
}
// Return the selected ToolboxItem
public System.Drawing.Design.ToolboxItem GetSelectedToolboxItem(System.ComponentModel.Design.IDesignerHost host)
{
return GetSelectedToolboxItem();
}
// Return the selected ToolboxItem
public System.Drawing.Design.ToolboxItem GetSelectedToolboxItem()
{
if(toolBox == null)
return null;
return (System.Drawing.Design.ToolboxItem)toolBox.SelectedItem;
}
// Return the list of selected ToolboxItems
public System.Drawing.Design.ToolboxItemCollection GetToolboxItems(string category, System.ComponentModel.Design.IDesignerHost host)
{
return GetToolboxItems();
}
// Return the list of selected ToolboxItems
public System.Drawing.Design.ToolboxItemCollection GetToolboxItems(string category)
{
return GetToolboxItems();
}
// Return the list of selected ToolboxItems
public System.Drawing.Design.ToolboxItemCollection GetToolboxItems(System.ComponentModel.Design.IDesignerHost host)
{
return GetToolboxItems();
}
// Return the list of selected ToolboxItems
public System.Drawing.Design.ToolboxItemCollection GetToolboxItems()
{
if (toolBox == null)
return null;
System.Drawing.Design.ToolboxItem[] t = new System.Drawing.Design.ToolboxItem[toolBox.Items.Count];
toolBox.Items.CopyTo(t, 0);
return new System.Drawing.Design.ToolboxItemCollection(t);
}
// Not use
public bool IsSupported(object serializedObject, System.Collections.ICollection filterAttributes)
{
return false;
}
// Not use
public bool IsSupported(object serializedObject, System.ComponentModel.Design.IDesignerHost host)
{
return false;
}
// Not use
public bool IsToolboxItem(object serializedObject, System.ComponentModel.Design.IDesignerHost host)
{
return false;
}
// Not use
public bool IsToolboxItem(object serializedObject)
{
return false;
}
// Not use
public void RemoveCreator(string format, System.ComponentModel.Design.IDesignerHost host)
{
}
// Not use
public void RemoveCreator(string format)
{
}
// Remove a toolboxItem from toolbox
public void RemoveToolboxItem(System.Drawing.Design.ToolboxItem toolboxItem, string category)
{
RemoveToolboxItem(toolboxItem);
}
// Remove a toolboxItem from toolbox
public void RemoveToolboxItem(System.Drawing.Design.ToolboxItem toolboxItem)
{
if (toolBox == null)
return;
toolBox.SelectedItem = null;
toolBox.Items.Remove(toolboxItem);
}
// Not use
public string SelectedCategory
{
get
{
return null;
}
set
{
}
}
// Indicate that a toolboxItem was used, one puts the selection of the toolbox at null
public void SelectedToolboxItemUsed()
{
if (toolBox == null)
return;
toolBox.SelectedItem = null;
}
// Serialize the toolboxItem necessary for the drag and drop
public object SerializeToolboxItem(System.Drawing.Design.ToolboxItem toolboxItem)
{
DataObject dataObject = new DataObject();
dataObject.SetData(typeof(System.Drawing.Design.ToolboxItem), toolboxItem);
return dataObject;
}
// Indicate if a cursor is to use if a toolboxItem is selected
public bool SetCursor()
{
if (view == null)
return false;
if (toolBox.SelectedItem != null)
{
view.Cursor = Cursors.Cross;
return true;
}
return false;
}
// Define a toolboxItem to be selected on the toolBox
public void SetSelectedToolboxItem(System.Drawing.Design.ToolboxItem toolboxItem)
{
if (toolBox == null)
return;
toolBox.SelectedItem = toolboxItem;
}
// Refresh the toolbox
public void Refresh()
{
toolBox.Refresh();
}
} |