示例#1
0
        //- Gets a new DesignSurfaceExt2
        //- and loads it with the appropriate type of root component.
        public DesignSurfaceExt2 CreateDesignSurfaceExt2()
        {
            //- with a DesignSurfaceManager class, is useless to add new services
            //- to every design surface we are about to create,
            //- because of the "IServiceProvider" parameter of CreateDesignSurface(IServiceProvider) Method.
            //- This param let every design surface created
            //- to use the services of the DesignSurfaceManager.
            //- A new merged service provider will be created that will first ask
            //- this provider for a service, and then delegate any failures
            //- to the design surface manager object.
            //- Note:
            //-     the following line of code create a brand new DesignSurface which is added
            //-     to the Designsurfeces collection,
            //-     i.e. the property "this.DesignSurfaces" ( the .Count in incremented by one)
            DesignSurfaceExt2 surface = (DesignSurfaceExt2)(this.CreateDesignSurface(this.ServiceContainer));
            //- each time a brand new DesignSurface is created,
            //- subscribe our handler to its SelectionService.SelectionChanged event
            //- to sync the PropertyGridHost
            ISelectionService selectionService = (ISelectionService)(surface.GetService(typeof(ISelectionService)));

            if (null != selectionService)
            {
                selectionService.SelectionChanged += (object sender, EventArgs e) =>
                {
                    ISelectionService selectService = sender as ISelectionService;
                    if (null == selectService)
                    {
                        return;
                    }
                    if (0 == selectService.SelectionCount)
                    {
                        return;
                    }
                    //- Sync the PropertyGridHost
                    //PropertyGrid propertyGrid = (PropertyGrid)this.GetService(typeof(PropertyGrid));
                    CustomPropertyGridHost propertyGrid = (CustomPropertyGridHost)this.GetService(typeof(CustomPropertyGridHost));
                    if (null == propertyGrid)
                    {
                        return;
                    }
                    ArrayList comps = new ArrayList();
                    comps.AddRange(selectService.GetSelectedComponents());
                    propertyGrid.SelectedObject = comps[0];
                    if (propertyGrid.reportCtrlProp != null)
                    {
                        updateStatusBar(propertyGrid.reportCtrlProp.reportControlProperty);
                    }
                };
            }
            DesignSurfaceExt2Collection.Add(surface);
            this.ActiveDesignSurface = surface;
            //- and return the DesignSurface (to let the its BeginLoad() method to be called)
            return(surface);
        }
示例#2
0
 //-
 private void Init()
 {
     this.PropertyGridHost = new CustomPropertyGridHost(this);
     //- add the PropertyGridHost and ComboBox as services
     //- to let them available for every DesignSurface
     //- (the DesignSurface need a PropertyGridHost/ComboBox not a the UserControl hosting them so
     //- we provide the PropertyGridHost/ComboBox embedded inside our UserControl PropertyGridExt)
     this.ServiceContainer.AddService(typeof(PropertyGrid), PropertyGridHost.PropertyGrid);
     this.ServiceContainer.AddService(typeof(CustomPropertyGridHost), PropertyGridHost);
     this.PropertyGridHost.invokeUpdate += PropertyGridHost_invokeUpdate;
     //this.ServiceContainer.AddService( typeof( ComboBox ), PropertyGridHost.ComboBox );
     this.ActiveDesignSurfaceChanged += (object sender, ActiveDesignSurfaceChangedEventArgs e) =>
     {
         DesignSurfaceExt2 surface = e.NewSurface as DesignSurfaceExt2;
         if (null == surface)
         {
             return;
         }
         UpdatePropertyGridHost(surface);
     };
 }