//- The DesignSurface class provides several design-time services automatically.
 //- The DesignSurface class adds all of its services in its constructor.
 //- Most of these services can be overridden by replacing them in the
 //- protected ServiceContainer property.To replace a service, override the constructor,
 //- call base, and make any changes through the protected ServiceContainer property.
 private void InitServices()
 {
     //- each DesignSurface has its own default services
     //- We can leave the default services in their present state,
     //- or we can remove them and replace them with our own.
     //- Now add our own services using IServiceContainer
     //-
     //-
     //-
     _menuCommandService = new MenuCommandServiceExt(this);
     if (_menuCommandService != null)
     {
         //- remove the old Service, i.e. the DesignsurfaceExt service
         this.ServiceContainer.RemoveService(typeof(IMenuCommandService), false);
         //- add the new IMenuCommandService
         this.ServiceContainer.AddService(typeof(IMenuCommandService), _menuCommandService);
     }
     //-
     //-
     //- IToolboxService
     _toolboxService = new ToolboxServiceImp(this.GetIDesignerHost());
     if (_toolboxService != null)
     {
         this.ServiceContainer.RemoveService(typeof(IToolboxService), false);
         this.ServiceContainer.AddService(typeof(IToolboxService), _toolboxService);
     }
 }
        public void EnableDragandDrop()
        {
            // For the management of the drag and drop of the toolboxItems
            Control ctrl = this.GetView();

            if (null == ctrl)
            {
                return;
            }
            ctrl.AllowDrop = true;
            ctrl.DragDrop += new DragEventHandler(OnDragDrop);

            //- enable the Dragitem inside the our Toolbox
            ToolboxServiceImp tbs = this.GetIToolboxService();

            if (null == tbs)
            {
                return;
            }
            if (null == tbs.Toolbox)
            {
                return;
            }
            tbs.Toolbox.MouseDown += new MouseEventHandler(OnListboxMouseDown);
        }
예제 #3
0
        private DesignSurfaceExt2 CreateDesignSurface()
        {
            //- step.0
            //- create a DesignSurface and put it inside a Form in DesignTime
            DesignSurfaceExt2 surface = new DesignSurfaceExt2();
            //-
            //-
            IDesignSurfaceExt2 isurf = (IDesignSurfaceExt2)surface;

            this._listOfDesignSurface.Add(isurf);
            //- step.1
            //- enable the UndoEngines
            isurf.GetUndoEngineExt().Enabled = true;
            //- step.2
            //- try to get a ptr to ISelectionService interface
            //- if we obtain it then hook the SelectionChanged event
            ISelectionService selectionService = (ISelectionService)(isurf.GetIDesignerHost().GetService(typeof(ISelectionService)));

            if (null != selectionService)
            {
                selectionService.SelectionChanged += new System.EventHandler(OnSelectionChanged);
            }
            //- step.3
            //- Select the service IToolboxService
            //- and hook it to our ListBox
            ToolboxServiceImp tbox = isurf.GetIToolboxService() as ToolboxServiceImp;

            if (null != tbox)
            {
                tbox.Toolbox = listBox1;
            }
            //-
            //- finally return the Designsurface
            return(surface);
        }
        //- Management of the Drag&Drop of the toolboxItems contained inside our Toolbox
        private void OnListboxMouseDown(object sender, MouseEventArgs e)
        {
            ToolboxServiceImp tbs = this.GetIToolboxService();

            if (null == tbs)
            {
                return;
            }
            if (null == tbs.Toolbox)
            {
                return;
            }
            if (null == tbs.Toolbox.SelectedItem)
            {
                return;
            }

            tbs.Toolbox.DoDragDrop(tbs.Toolbox.SelectedItem, DragDropEffects.Copy | DragDropEffects.Move);
        }