I'm currently working of a project where my part is to design a Design Surface where the end user can add/remove/move controls at run-time.
I followed this tutorial "Hosting Windows Forms Designers, by Tim Dawson", and almost have implemented all the features I need.
Short story for those who don't want to read the tutorial : I implemented IDesignerHost
, IContainer
, ISelectionService
, IToolboxService
and some other interface, to create my design surface. I didn't use the System.ComponentModel.Design.DesignSurface
already in the framework, mainly beacause I need a really custom design surface.
Question :
I want to allow user to drag & drop new Control
from the IToolboxService
to the IDesignerHost/IContainer
. In this tutorial, you clic on a Control
in the toolbox, the click on the design surface to add the control.
What i've found :
- There is a built-in feature that
automagically does drag & drop from
IToolboxService
toSystem.ComponentModel.Design.DesignSurface
but it is clearly not working if you implement IDesignerHost from nothing. When you use the
Control.DoDragDrop(ToolboxItem)
method, to initiate a drag & drop :IToolboxService.SerializeToolboxItem(ToolboxItem)
is called to serialize the itemIToolboxService.IsToolboxItem(object)
andIToolboxService.IsSupported(object)
are called to evaluate if the
serialized ToolboxItem can be allowed to be droped on the design surface- When you drop the control :
IToolboxService.DeserializeToolboxItem(object serializedObject)
is called by the design surface to deserialize the controldropped.
IToolboxService.SetCursor()
is called to know if you define a custom cursor, or let the standard windows cursor.
Problem :
I implemented all mentionned above, in the "What i've found", but the drag & drop is buggy :
- I drag, everything's fine, but when
hovering the design surface, my
cursor blink a little between
standard cursor and the
"
DragDropEffects.Copy
" style. - When I drop, nothing happens, and when my cursor leave the design surface (after I dropped), then the new
Control
is created and added where I dropped it.
Has anyone ever tried to do what I'm doing, and if so, how did you manage it ? Is there anyone that has any pointer/link/good advices ?
Thank you =)