Windows Develop Bookmark and Share   
 index > Windows Forms Designer > IToolboxService and the DesignSurface class
 

IToolboxService and the DesignSurface class

I am trying to use the DesignSurface in VS 2k5 Beta2 and I'm a bit confused when it comes to the interaction between it and the IToolboxService.

I have an implementation of the IToolboxService and I have added it to the DesignerHost. My toolbox service uses a treeview to show the controls available and in each category (root nodes) I have a selection pointer node and various other windows forms control nodes.

When I drag say a button ToolboxItem on to the surface I get a button. I then react to the SelectedToolboxItemUsed method on IToolboxService to change the selected node in the tree to the selection pointer.

If I then click on the design surface my implementation of GetSelectedToolboxItem is called. Can anyone tell me what the designer framework uses the returned ToolboxItem for? It seems to me that the designer is adding new controls to the surface depending on the return value from this method, but not always!!

Just on the off chance this sounds familiar to someone, my designer has a problem in that as soon as I have added say, a button, to the surface I cannot seem to select any other control on the surface.

Regards

Graham

Gravy  Friday, July 22, 2005 3:03 PM
Ok, so I have found a better / easier way of doing this. At the beginning of all this I started off with the following article http://msdn.microsoft.com/msdnmag/issues/04/12/CustomFormsDesigner/default.aspx which described how to do a custom forms designer for .NET 1.1. From there I went on to changing the sample to include the DesignSurface in .NET 2.0. What I didn't realise until recently is that .NET 2.0 also provides a default implementation of the ToolboxService which was where I was having a little trouble. Changing over to this implementation (well actually I mean deriving my own class from this abstract class) all my troubles have gone away. For now anyway :)

Thanks

Graham
Gravy  Monday, July 25, 2005 8:31 AM
Ok, so I have found a better / easier way of doing this. At the beginning of all this I started off with the following article http://msdn.microsoft.com/msdnmag/issues/04/12/CustomFormsDesigner/default.aspx which described how to do a custom forms designer for .NET 1.1. From there I went on to changing the sample to include the DesignSurface in .NET 2.0. What I didn't realise until recently is that .NET 2.0 also provides a default implementation of the ToolboxService which was where I was having a little trouble. Changing over to this implementation (well actually I mean deriving my own class from this abstract class) all my troubles have gone away. For now anyway :)

Thanks

Graham
Gravy  Monday, July 25, 2005 8:31 AM
Hi Graham,
does it mean you also figured out how to get a ToolboxItem out of ToolbosItemContainer? There is ToolbosItemContainer.GetToolboxItem(...) that takes a collection of creators as a param. Do you have any idea what these creators are about?
Thanks,
- Andrey
AKORNICH  Tuesday, August 23, 2005 12:16 AM
Andrey,

I didn't need to specifally get a Toolbox item. My ToolboxService derived class contained an array of toolbox items, in their appropriate toolbox item container. This was populated in the ctor as in:

uiToolboxItems.Add(new ToolboxItemContainer(new ToolboxItem(typeof(Label))));
uiToolboxItems.Add(new ToolboxItemContainer(new ToolboxItem(typeof(Button))));
uiToolboxItems.Add(new ToolboxItemContainer(new ToolboxItem(typeof(TextBox))));
uiToolboxItems.Add(new ToolboxItemContainer(new ToolboxItem(typeof(TabControl))));



And then when I needed to populate my tree view of toolbox item controls I used:

ToolboxItemCollection tools = toolboxService.GetToolboxItems(categoryName);
foreach (ToolboxItem toolItem in tools)
{
...
<Create tree node and add toolItem reference to the Tag
...
}


And then, during a mouse down handler on the tree view I initiated the drag operation with the toolbox item like...


ToolboxItem item = clickedNode.Tag as ToolboxItem;
// if its not the pointer tool
if (string.Compare(item.DisplayName, "Pointer", true) != 0)
{
    // serialize the item and send it over
    DataObject dataObj = toolboxService.SerializeToolboxItem(item) as DataObject;
    DoDragDrop(dataObj, DragDropEffects.Copy);
}


Hope this helps.

Graham

Gravy  Tuesday, August 23, 2005 8:27 AM
Graham, thank you for helping!
I had a different design in mind. But I actualy like your approach more. I'll just follow the same pattern.
Thank you very much,
- Andrey
AKORNICH  Tuesday, August 23, 2005 5:00 PM

You can use google to search for other answers

Custom Search

More Threads

• The Perfect Host - MSDN March 2006 Article - VB.NET Code
• Strange Behaviour of Combobox created as Custom by inheriting from Actual
• Designer Background
• TabPage crash in design time with child controls
• Windows Control (Dont know the name)
• Class not registered
• Displaying DataGridViewColumn-derived classes in the ColumnType property of the Edit Columns dialog box
• Could not load file or assembly Interop.SHDocVw
• Show control (not inherited from UserControl) in design time
• creating toolbar user control