예제 #1
0
        public void UpdatePropertyGridHost(DesignSurfaceExt2 surface, ComponentEventArgs e)
        {
            IDesignerHost host = (IDesignerHost)surface.GetService(typeof(IDesignerHost));

            if (null == host)
            {
                return;
            }
            if (null == host.RootComponent)
            {
                return;
            }
            //- sync the PropertyGridHost
            if (host.TransactionDescription == null)
            {
                return;
            }

            string[] transactionArr = host.TransactionDescription.Split(' ');
            //if (transactionArr[0] == "Move" || transactionArr[0] == "Resize")
            if (transactionArr[0] != "Move" && transactionArr[0] != "Resize")
            {
                if (transactionArr[0] == "Delete")
                {
                    this.PropertyGridHost.DeleteReportControlPropertyItem(e.Component.Site.Name);
                }
                this.PropertyGridHost.SelectedObject = host.RootComponent;
            }
            else
            {
                this.PropertyGridHost.SelectedObject = this.PropertyGridHost.SelectedObject;
            }
        }
예제 #2
0
        //public PropertyGrid GetPropertyGridHost(DesignSurfaceExt2 surface, Control c)
        //{
        //    IDesignerHost host = (IDesignerHost)surface.GetService(typeof(IDesignerHost));

        //    //- sync the PropertyGridHost
        //    this.PropertyGridHost.SelectedObject = host.RootComponent;
        //    return this.PropertyGridHost.PropertyGrid;
        //    //return this.PropertyGridHost.PropertyGrid;

        //}

        public CustomPropertyGridHost GetPropertyGridHost(DesignSurfaceExt2 surface, Control c)
        {
            IDesignerHost host = (IDesignerHost)surface.GetService(typeof(IDesignerHost));

            //- sync the PropertyGridHost
            this.PropertyGridHost.SelectedObject = host.RootComponent;
            return(this.PropertyGridHost);
            //return this.PropertyGridHost.PropertyGrid;
        }
예제 #3
0
        public void UpdatePropertyGridHost(DesignSurfaceExt2 surface)
        {
            var host = (IDesignerHost)surface.GetService(typeof(IDesignerHost));
            if (host?.RootComponent == null)
                return;

            //- sync the PropertyGridHost
            this.PropertyGridHost.SelectedObject = host.RootComponent;
            this.PropertyGridHost.ReloadComboBox();
        }
        //- 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));
                    if (null == propertyGrid)
                    {
                        return;
                    }

                    ArrayList comps = new ArrayList();
                    comps.AddRange(selectService.GetSelectedComponents());
                    propertyGrid.SelectedObjects = comps.ToArray();
                };
            }
            DesignSurfaceExt2Collection.Add(surface);
            this.ActiveDesignSurface = surface;

            //- and return the DesignSurface (to let the its BeginLoad() method to be called)
            return(surface);
        }
예제 #5
0
        public void UpdatePropertyGridHost(DesignSurfaceExt2 surface)
        {
            IDesignerHost host = (IDesignerHost)surface.GetService(typeof(IDesignerHost));

            if (null == host)
            {
                return;
            }
            if (null == host.RootComponent)
            {
                return;
            }
            //- sync the PropertyGridHost
            if (host.TransactionDescription == null)
            {
                return;
            }

            string[]          transactionArr   = host.TransactionDescription.Split(' ');
            ISelectionService selectionService = (ISelectionService)(ActiveDesignSurface.GetService(typeof(ISelectionService)));
            ICollection       i = selectionService.GetSelectedComponents();

            //if (transactionArr[0] == "Move" || transactionArr[0] == "Resize")
            if (transactionArr[0] != "Move" && transactionArr[0] != "Resize")
            {
                //if (transactionArr[0] == "Delete")
                //{
                //    this.PropertyGridHost.DeleteReportControlPropertyItem();
                //}
                this.PropertyGridHost.SelectedObject = host.RootComponent;
            }
            else
            {
                this.PropertyGridHost.SelectedObject = this.PropertyGridHost.SelectedObject;
                updateStatusBar(this.PropertyGridHost.reportCtrlProp.reportControlProperty);
            }
        }
예제 #6
0
        //- Create the DesignSurface and the rootComponent (a .NET Control)
        //- using IDesignSurfaceExt.CreateRootComponent()
        //- if the alignmentMode doesn't use the GRID, then the gridSize param is ignored
        //- Note:
        //-     the generics param is used to know which type of control to use as RootComponent
        //-     TT is requested to be derived from .NET Control class
        public DesignSurfaceExt2 AddDesignSurface <TT> (
            int startingFormWidth, int startingFormHeight,
            AlignmentModeEnum alignmentMode, Size gridSize
            ) where TT : Control
        {
            const string _signature_ = _Name_ + @"::AddDesignSurface<>()";

            if (!this)
            {
                throw new Exception(_signature_ + " - Exception: " + _Name_ + " is not initialized! Please set the Property: IpDesigner::Toolbox before calling any methods!");
            }
            //HRulerPixel.MouseTrackingOn = true;
            //HRulerCm.MouseTrackingOn = true;
            //VRulerCM.MouseTrackingOn = true;
            //VRulerPixel.MouseTrackingOn = true;

            //if (gridSize.Height > 700)
            //{
            //    VRulerPixel.Height = VRulerCM.Height = gridSize.Height;

            //}
            //else
            //{
            //    VRulerPixel.Height = VRulerCM.Height = panel1.Height;
            //}

            //- step.0
            //- create a DesignSurface
            DesignSurfaceExt2 surface = DesignSurfaceManager.CreateDesignSurfaceExt2();

            this.DesignSurfaceManager.ActiveDesignSurface = surface;


            //this.DesignSurfaceParent_pnl.Size = gridSize;

            //this.splitterpDesigner.Dock = DockStyle.None;
            //this.splitterpDesigner.Size = this.splitterpDesigner.Parent.Size;

            //-
            //-
            //- step.1
            //- choose an alignment mode...
            switch (alignmentMode)
            {
            case AlignmentModeEnum.SnapLines:
                surface.UseSnapLines();
                break;

            case AlignmentModeEnum.Grid:
                surface.UseGrid(gridSize);
                break;

            case AlignmentModeEnum.GridWithoutSnapping:
                surface.UseGridWithoutSnapping(gridSize);
                break;

            case AlignmentModeEnum.NoGuides:
                surface.UseNoGuides();
                break;

            default:
                surface.UseSnapLines();
                break;
            }
            //end_switch
            //-
            //-
            //- step.2
            //- enable the UndoEngine
            ((IDesignSurfaceExt)surface).GetUndoEngineExt().Enabled = true;
            //-
            //-
            //- step.3
            //- Select the service IToolboxService
            //- and hook it to our ListBox
            ToolboxServiceImp tbox = ((IDesignSurfaceExt2)surface).GetIToolboxService() as ToolboxServiceImp;

            //- we don't check if Toolbox is null because the very first check: if(!this)...
            if (null != tbox)
            {
                tbox.Toolbox = this.Toolbox;
            }
            //-
            //-
            //- step.4
            //- create the Root compoment, in these cases a Form
            //- cast to .NET Control because the TT object
            //- has a constraint: to be a ".NET Control"
            rootComponent = surface.CreateRootComponent(typeof(TT), new Size(startingFormWidth, startingFormHeight)) as Control;
            //rootComponent.Location = new Point(32, 32);
            //- rename the Sited component
            //- (because the user may add more then one Form
            //- and every new Form will be called "Form1"
            //- if we don't set its Name)
            rootComponent.Site.Name = this.DesignSurfaceManager.GetValidFormName();
            //rootComponent.Location = new Point(32, 32);
            this.DesignSurfaceParent_pnl.Location = rootComponent.Location;
            //-
            //-
            //- step.5
            //- enable the Drag&Drop on RootComponent
            //((DesignSurfaceExt2) surface).EnableDragandDrop();
            //-
            //-
            //- step.6
            //- IComponentChangeService is marked as Non replaceable service
            componentChangeService = (IComponentChangeService)(surface.GetService(typeof(IComponentChangeService)));
            if (null != componentChangeService)
            {
                //- the Type "ComponentEventHandler Delegate" Represents the method that will
                //- handle the ComponentAdding, ComponentAdded, ComponentRemoving, and ComponentRemoved
                //- events raised for component-level events
                componentChangeService.ComponentChanged += (Object sender, ComponentChangedEventArgs e) =>
                {
                    // do nothing
                    DesignSurfaceManager.UpdatePropertyGridHost(surface);
                };
                //System.ComponentModel.Design.DesignerActionUIStateChangeEventHandler
                componentChangeService.ComponentChanging += (Object sender, ComponentChangingEventArgs e) =>
                {
                    DesignSurfaceManager.UpdatePropertyGridHost(surface);
                };
                componentChangeService.ComponentAdded += (Object sender, ComponentEventArgs e) =>
                {
                    DesignSurfaceManager.UpdatePropertyGridHost(surface);
                };
                //componentChangeService.ComponentRemoved += ( Object sender, ComponentEventArgs e )=>
                //{
                //    DesignSurfaceManager.UpdatePropertyGridHost( surface );
                //};
                componentChangeService.ComponentRemoved += (Object sender, ComponentEventArgs e) =>
                {
                    DesignSurfaceManager.UpdatePropertyGridHost(surface, e);
                };
            }
            //DesignSurfaceManager.PropertyGridHost.SelectedObject = rootComponent;
            //-
            //-
            //- step.7
            //- now set the Form::Text Property
            //- (because it will be an empty string
            //- if we don't set it)
            view = surface.GetView();


            if (null == view)
            {
                return(null);
            }
            // view = surface.GetView(ref DesignSurfaceParent_pnl);
            DesignSurfaceParent_pnl.MouseClick += DesignSurfaceParent_pnl_MouseClick;
            DesignSurfaceParent_pnl.MouseWheel += DesignSurfaceParent_pnl_MouseWheel;
            //   view = viewObject as Control;
            PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(view);

            //- Sets a PropertyDescriptor to the specific property
            PropertyDescriptor pdS = pdc.Find("Text", false);

            if (null != pdS)
            {
                pdS.SetValue(rootComponent, rootComponent.Site.Name + " (design mode)");
            }
            //-
            //-
            //- step.8
            //- display the DesignSurface
            string sTabPageText = rootComponent.Site.Name;

            // TabPage newPage = new TabPage( sTabPageText );
            // newPage.Name = sTabPageText;
            splitterpDesigner.Panel1.SuspendLayout();
            DesignSurfaceParent_pnl.SuspendLayout();
            DesignSurfaceParent_pnl.MouseClick += DesignSurfaceParent_pnl_MouseClick;
            // newPage.SuspendLayout(); //----------------------------------------------------
            //view.Dock = DockStyle.Left;
            //view.BackColor = Color.Red;
            view.Parent = DesignSurfaceParent_pnl; //- Note this assignment
            //view.BackColor = Color.Red;
            //view.Parent = splitterpDesigner.Panel1;
            // DesignSurfaceParent_pnl.Controls.Add(view);
            splitterpDesigner.Panel1.ResumeLayout();
            DesignSurfaceParent_pnl.ResumeLayout();
            //DesignSurfaceParent_pnl.Visible = true;
            //DesignSurfaceParent_pnl.MouseWheel += DesignSurfaceParent_pnl_MouseWheel;
            //DesignSurfaceParent_pnl.HorizontalScroll.Maximum = 0;
            //DesignSurfaceParent_pnl.AutoScroll = false;
            //DesignSurfaceParent_pnl.VerticalScroll.Visible = false;
            //DesignSurfaceParent_pnl.AutoScroll = true;
            DesignSurfaceParent_pnl.BringToFront();
            DesignSurfaceParent_pnl.Focus();
            // DesignSurfaceParent_pnl.Parent = splitterpDesigner.Panel1;
            //this.tbCtrlpDesigner.TabPages.Add( newPage );
            // newPage.ResumeLayout(); //-----------------------------------------------------
            //splitterpDesigner.Panel1.ResumeLayout();
            //splitterpDesigner.Panel1.Height = gridSize.Height;
            //- select the TabPage created
            //this.tbCtrlpDesigner.SelectedIndex = this.tbCtrlpDesigner.TabPages.Count - 1;
            //-
            //-
            //- step.9
            //- finally return the DesignSurface created to let it be modified again by user
            return(surface);
        }
예제 #7
0
        //- Create the DesignSurface and the rootComponent (a .NET Control)
        //- using IDesignSurfaceExt.CreateRootComponent()
        //- if the alignmentMode doesn't use the GRID, then the gridSize param is ignored
        //- Note:
        //-     the generics param is used to know which type of control to use as RootComponent
        //-     TT is requested to be derived from .NET Control class
        public DesignSurfaceExt2 AddDesignSurface <TT> (
            int startingFormWidth, int startingFormHeight,
            AlignmentModeEnum alignmentMode, Size gridSize
            ) where TT : Control
        {
            const string _signature_ = _Name_ + @"::AddDesignSurface<>()";

            if (!this)
            {
                throw new Exception(_signature_ + " - Exception: " + _Name_ + " is not initialized! Please set the Property: IpDesigner::Toolbox before calling any methods!");
            }


            //- step.0
            //- create a DesignSurface
            DesignSurfaceExt2 surface = DesignSurfaceManager.CreateDesignSurfaceExt2();

            this.DesignSurfaceManager.ActiveDesignSurface = surface;
            //-
            //-
            //- step.1
            //- choose an alignment mode...
            switch (alignmentMode)
            {
            case AlignmentModeEnum.SnapLines:
                surface.UseSnapLines();
                break;

            case AlignmentModeEnum.Grid:
                surface.UseGrid(gridSize);
                break;

            case AlignmentModeEnum.GridWithoutSnapping:
                surface.UseGridWithoutSnapping(gridSize);
                break;

            case AlignmentModeEnum.NoGuides:
                surface.UseNoGuides();
                break;

            default:
                surface.UseSnapLines();
                break;
            }//end_switch
            //-
            //-
            //- step.2
            //- enable the UndoEngine
            ((IDesignSurfaceExt)surface).GetUndoEngineExt().Enabled = true;
            //-
            //-
            //- step.3
            //- Select the service IToolboxService
            //- and hook it to our ListBox
            ToolboxServiceImp tbox = ((IDesignSurfaceExt2)surface).GetIToolboxService() as ToolboxServiceImp;

            //- we don't check if Toolbox is null because the very first check: if(!this)...
            if (null != tbox)
            {
                tbox.Toolbox = this.Toolbox;
            }
            //-
            //-
            //- step.4
            //- create the Root compoment, in these cases a Form
            Control rootComponent = null;

            //- cast to .NET Control because the TT object
            //- has a constraint: to be a ".NET Control"
            rootComponent = surface.CreateRootComponent(typeof(TT), new Size(startingFormWidth, startingFormHeight)) as Control;
            //- rename the Sited component
            //- (because the user may add more then one Form
            //- and every new Form will be called "Form1"
            //- if we don't set its Name)
            rootComponent.Site.Name = this.DesignSurfaceManager.GetValidFormName();
            //-
            //-
            //- step.5
            //- enable the Drag&Drop on RootComponent
            ((DesignSurfaceExt2)surface).EnableDragandDrop();
            //-
            //-
            //- step.6
            //- IComponentChangeService is marked as Non replaceable service
            IComponentChangeService componentChangeService = (IComponentChangeService)(surface.GetService(typeof(IComponentChangeService)));

            if (null != componentChangeService)
            {
                //- the Type "ComponentEventHandler Delegate" Represents the method that will
                //- handle the ComponentAdding, ComponentAdded, ComponentRemoving, and ComponentRemoved
                //- events raised for component-level events
                componentChangeService.ComponentChanged += (Object sender, ComponentChangedEventArgs e) =>
                {
                    // do nothing
                };
                componentChangeService.ComponentAdded += (Object sender, ComponentEventArgs e) =>
                {
                    DesignSurfaceManager.UpdatePropertyGridHost(surface);
                };
                componentChangeService.ComponentRemoved += (Object sender, ComponentEventArgs e) =>
                {
                    DesignSurfaceManager.UpdatePropertyGridHost(surface);
                };
            }
            //-
            //-
            //- step.7
            //- now set the Form::Text Property
            //- (because it will be an empty string
            //- if we don't set it)
            Control view = surface.GetView();

            if (null == view)
            {
                return(null);
            }
            PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(view);
            //- Sets a PropertyDescriptor to the specific property
            PropertyDescriptor pdS = pdc.Find("Text", false);

            if (null != pdS)
            {
                pdS.SetValue(rootComponent, rootComponent.Site.Name + " (design mode)");
            }
            //-
            //-
            //- step.8
            //- display the DesignSurface
            string  sTabPageText = rootComponent.Site.Name;
            TabPage newPage      = new TabPage(sTabPageText);

            newPage.Name = sTabPageText;
            newPage.SuspendLayout(); //----------------------------------------------------
            view.Dock   = DockStyle.Fill;
            view.Parent = newPage;   //- Note this assignment
            this.tbCtrlpDesigner.TabPages.Add(newPage);
            newPage.ResumeLayout();  //-----------------------------------------------------
            //- select the TabPage created
            this.tbCtrlpDesigner.SelectedIndex = this.tbCtrlpDesigner.TabPages.Count - 1;
            //-
            //-
            //- step.9
            //- finally return the DesignSurface created to let it be modified again by user
            return(surface);
        }
        public DesignSurfaceExt2 AddReportSectionDesignSurface(Control parent, ReportDesignerUserControl rduc)
        {
            this.ReportDesignerUserControl = rduc;

            DesignSurfaceExt2 surface = DesignSurfaceManager.CreateDesignSurfaceExt2();

            this.DesignSurfaceManager.ActiveDesignSurface = surface;
            surface.UseSnapLines();
            surface.GetUndoEngineExt().Enabled   = true;
            surface.GetIToolboxService().Toolbox = this.Toolbox;

            Control rootComponent = surface.CreateRootComponent(typeof(EbReportPanel), new Size(1, 1)) as Control;

            rootComponent.Site.Name = this.DesignSurfaceManager.GetValidFormName();
            (rootComponent as EbReportPanel).ReportDesignerUserControl = this.ReportDesignerUserControl;
            surface.EnableDragandDrop(); // DO THIS AFTER CREATING rootComponent

            IComponentChangeService componentChangeService = (IComponentChangeService)(surface.GetService(typeof(IComponentChangeService)));

            if (null != componentChangeService)
            {
                componentChangeService.ComponentChanged += (Object sender, ComponentChangedEventArgs e) =>
                {
                    if (e.Component is IEbControl)
                    {
                        (e.Component as IEbControl).DoDesignerRefresh();
                    }
                };

                componentChangeService.ComponentAdding += (Object sender, ComponentEventArgs e) =>
                {
                    if (surface.GetIToolboxService().Toolbox.SelectedItem != null)
                    {
                        var fieldname = (surface.GetIToolboxService().Toolbox.SelectedItem as ToolboxItem).DisplayName;
                        if (e.Component is EbReportFieldTextControl)
                        {
                            (e.Component as EbReportFieldTextControl).EbControl.Name  = fieldname;
                            (e.Component as EbReportFieldTextControl).EbControl.Label = fieldname;
                        }
                        else if (e.Component is EbReportFieldNumericControl)
                        {
                            (e.Component as EbReportFieldNumericControl).EbControl.Name  = fieldname;
                            (e.Component as EbReportFieldNumericControl).EbControl.Label = fieldname;
                        }
                    }
                };

                componentChangeService.ComponentAdded   += (Object sender, ComponentEventArgs e) => { DesignSurfaceManager.UpdatePropertyGridHost(surface); };
                componentChangeService.ComponentRemoved += (Object sender, ComponentEventArgs e) => { DesignSurfaceManager.UpdatePropertyGridHost(surface); };
            }

            Control view = surface.GetView();

            if (null == view)
            {
                return(null);
            }

            view.Dock   = DockStyle.Fill;
            view.Parent = parent;

            return(surface);
        }