Hi, Hongye.I have tried reparenting a few different ways, but they all had the same effect.Presently, I and just moving the dropped controlusing the control designer's Control property that have cast to my control type so that I can access the internal FlowPayoutPanel.
protected override void OnDragDrop(DragEventArgs de)
{
DesignerTransaction transaction = null;
IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost));
IComponentChangeService changeService = (IComponentChangeService)GetService(typeof(IComponentChangeService));
IToolboxService toolboxService = (IToolboxService)GetService(typeof(IToolboxService));
ToolboxItem toolboxItem = toolboxService.GetSelectedToolboxItem();
if (toolboxItem != null)
{
//Dropping a toolbox item
//TODO: Finish this section after proof of concept
transaction = host.CreateTransaction("MovingDroppedToolboxControl");
IComponent[] comps = toolboxItem.CreateComponents();
changeService.OnComponentChanging(this.control.Toolbar, null);
this.control.Toolbar.Controls.Add(comps[0] as Control);
changeService.OnComponentChanged(this.control.Toolbar, null, null, null);
transaction.Commit();
}
else if (!(this.Control as FlowToolbar).flowLayoutPanel.Contains(this.controlBeingDragged))
{
if (host != null && changeService != null)
{
transaction = host.CreateTransaction("MovingControl");
changeService.OnComponentChanging(control.Toolbar, null);
control.Toolbar.Controls.Add(this.controlBeingDragged);
changeService.OnComponentChanged(this.control.Toolbar, null, null, null);
transaction.Commit();
(this.Control as FlowToolbar).flowLayoutPanel.PerformLayout();
(this.Control as FlowToolbar).LayoutChildren();
}
}
}
I've also tried doing it with a PropertyDescriptor.
PropertyDescriptor descriptor = TypeDescriptor.GetProperties(this.controlBeingDragged)["Parent"];
if (descriptor != null)
{
descriptor.SetValue(this.controlBeingDragged, this.Control as FlowToolbar).flowLayoutPanel);
}
LayoutChildren()from the code block above isa method in the FlowToolbar control and is whatI useat runtimefor laying out the controls (I will override the LayoutEngine before I finish the control). When I attach the debugger, I can see that when the designer calls this method, the reparented control is in the FlowLayoutPanel's Controls collection, butthe panel's GetPreferredSize() method ignores it.In Visual Studio, after the dropped control is reparented,if I try to resize the FlowToolbar with the mouse, the layout routine runs again and everything is fine. Seeing this, I thought maybe if I could spur thelayout of the controls in code and perhaps that would fix the issue. I have called "PerformLayout" (and all other manner of things) on the control the designer is attached to and on it's internal FlowLayoutPanel, but that has not helped. It might also be worth noting that everything works
fine in Visual Studio 2008. I only have this issue in 2005.
Thanks so much for your help!
Josh Usovsky