Controlling the ToolboxItem control type during a drag operation
-
I am currently writing a custom toolbox window for Visual Studio 2008, using the SDK. When the user drags from the list, I start a drag drop operation using ToolboxItem as the drag data. ToolboxItem tbi = new ToolboxItem(myControlType); IToolboxService serviceToolBox = (IToolboxService)GetService( typeof(IToolboxService)); object tbiSerialized = serviceToolBox.SerializeToolboxItem(tbi); this.DoDragDrop(tbiSerialized, DragDropEffects.Copy); When they drop the ToolBoxItem, I use the 'ToolboxItem.ComponentsCreated' event to write some extra setup code on the control void dropToolBoxItem_ComponentsCreated(object sender, ToolboxComponentsCreatedEventArgs e) { // write custom control config code here } However, I'm finding that I sometimes want control over the ToolboxItem control type, based on UI conditions during the drag. For example, I may want to create a different control on the designer if the user holds down the shift key. Sometimes I want to block the drop completely. Unfortunately, I don't see a way to change the ToolboxItem after I start the drag. It seems like the 'ToolboxItem.ComponentsCreating' event was meant for this kind of intervention, but I can't change the control type when the 'ToolboxItem.ComponentType' property is read only. I've tried a few hacks (like deleting the control after drop and re-creating the new control type), but none of it has worked out very well. Anyone have any ideas? Thanks, Aaron