Designer: Dragging of controls on the custom design surface.

Answered Designer: Dragging of controls on the custom design surface.

  • Wednesday, July 18, 2012 1:13 PM
     
     

    Hi, All.

    I has created custom designer with custom root component according this article, but I cannot dragging controls on custom design surface.

    I has attached simple project for illustration my problem.

    .NET language: C#

    To reproduce the problem:

    Create custom design surface.

    Any ideas or suggestions would be appreciated! Thanks!


All Replies

  • Thursday, July 19, 2012 6:57 AM
     
     

    Hi Dmitriy,

    I have read your codes. I think it is concerned about Winform Design.
     
    I will move it to Windows Forms Designer. I am trying to involve someone familiar with this topic to further look at this issue. There might be some time delay. Appreciate your patience.
     
    Thank you for your understanding and support.

    Best regards,


    Ego [MSFT]
    MSDN Community Support | Feedback to us

  • Thursday, July 19, 2012 11:07 AM
     
      Has Code

    Noticed an interesting difference in the outcome control in:

    internal void InitializeHost(HostSurface hostSurface)
    		{
    			try
    			{
    				if (hostSurface == null)
    					return;
    
    				_hostSurface = hostSurface;
    
    				Control control = _hostSurface.View as Control;<---our outcome control
    				control.Parent = this;
    				control.Dock = DockStyle.Fill;
    				control.Visible = true;
    			}
    			catch(Exception ex)
    			{
                    Trace.WriteLine(ex.ToString());
    			}
    		}

    If I create design surface from default components: Forms, UserControl, Component - outcome control inherits from DesignerFrame:

    If I create design surface from custom components - outcome control inherits from SampleRootdesigner+RootDesignerView:

    I think this explains the behavior of design surface with custom root control, which is not inherited from DesignerFrame, but how fix this I don't know.


  • Friday, July 20, 2012 8:38 AM
     
     
    I has updated attached project (DesignerHosting.zip). I has overrided OnDragDrop(), OnDragEnter() and other method in the RootDesignerView , as a result I have:
    1) if I drag of the tool's item on custom component using the IToolboxUser.ToolPicked() method - the tool's item is created in the designerHost.Container.Components and selected in the property grid, but this item is invisible;
    2) if I drag of the tool's item on custom component using the DoDragDrop() method, I have exception "Object reference not set to an instance of an object."
  • Tuesday, July 24, 2012 11:52 AM
     
     

    I have received answer on my problem from Microsoft Connect:

    "The sample code that you sent is calling DoDragDrop when the drop event is received and passes a ToolboxItem that is returned by CustomToolboxService.GetSelectedToolboxItem(). That function returns null and that gets passed to DoDragDrop, which throws an exception, as expected.
    There are at least two things that need changing here. First, the correct toolbox item needs to be available in the drop event handler. One possible way is persisting it in a member variable based on what gets passed during the dragdrop start event.
    The second issues is the use of DoDragDrop. That should be called at the beginning of the drag/drop action, not at the end. The correct way to get the control on the designers surface is to call the CreateComponents member of the toolbox item being dropped."

    Answer explains the causes of exception and how to create a ToolboxItem calling the CreateComponents(), but why custom designer does not display the added controls - is not clear???

    I has updated attached project (DesignerHosting.zip) according to the proposed solution of The Windows Forms Product Team, after creating of the component I add it in root component.Controls collection, but still have problem: custom designer does not display the added controls.


  • Thursday, July 26, 2012 6:24 PM
     
     

    On the basis of this, I have two cases:

    1. implement the IRootDesigner interface (because: “A root designer must implement the IRootDesigner interface” - as described in the MSDN documentation) in the SampleRootDesigner and creating the RootDesignerView, but in this case:
    • I have hidden drag/drop items;
    • I cannot do any action with drag/drop items (because they are hidden);
    • I cannot get or change any of properties of the RootDesignerView, because when fires selectionService_SelectionChanged() event of the HostSurface, the selected component is RootViewSampleComponent
    1. Refuse from implementing the IRootDesigner  interface in the SampleRootDesigner, but in this case:
    • The main my goal – filtering drag/drop items not working, because IToolboxUser.GetToolSupported() doesn’t work, it method always return TRUE.

    How then to combine the advantages of these two cases:

    • implement the IRootDesigner interface;
    • have a working IToolboxUser.GetToolSupported() method.
  • Friday, July 27, 2012 10:05 AM
     
     Answered Has Code
    I has found solution: all the problems were related to improper use the IRootDesigner and ParentControlDesigner, according to MSDN article:
    • I implement IRootDesigner interface in SampleRootDesigner:
        public class SampleRootDesigner : ParentControlDesigner, IRootDesigner, IToolboxUser
        {
    .....
    #region Implementation of IRootDesigner
    
            // IRootDesigner.SupportedTechnologies is a required override for an IRootDesigner.
            // This designer provides a display using the Windows Forms view technology.
            ViewTechnology[] IRootDesigner.SupportedTechnologies 
            {
                get { return new ViewTechnology[] {ViewTechnology.Default}; }
            }
    
            // This method returns an object that provides the view for this root designer. 
            object IRootDesigner.GetView(ViewTechnology technology) 
            {
                // If the design environment requests a view technology other than Windows 
                // Forms, this method throws an Argument Exception.
                if (technology != ViewTechnology.Default)            
                    throw new ArgumentException("An unsupported view technology was requested", 
                    "Unsupported view technology.");            
                
                // Creates the view object if it has not yet been initialized.
                if (view == null)                            
                    view = new RootDesignerView(this);          
      
                return view;
            }
    #endregion
    .....

    • I add IRootDesigner
       in to DesignerAttribute:
    [DesignerAttribute(typeof(SampleRootDesigner), typeof(IRootDesigner))]

    • I implement ParentControlDesigner in SampleRootDesigner:

    Solution:

    In my case I should:

    • only add IRootDesigner in DesignerAttribute of my RootDesignedComponent
    [DesignerAttribute(typeof(SampleRootDesigner), typeof(IRootDesigner))]
    • there is no need to implement  IRootDesigner in SampleRootDesigner
    • instead of the ParentControlDesigner  I use DocumentDesigner:
    public class SampleRootDesigner : DocumentDesigner, IToolboxUser