Esempio n. 1
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);
        }
Esempio n. 2
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);
        }
        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);
        }