Esempio n. 1
0
        private DesignSurfaceExt2 CreateDesignSurface()
        {
            //- step.0
            //- create a DesignSurface and put it inside a Form in DesignTime
            DesignSurfaceExt2  surface = this._mgr.CreateDesignSurfaceExt2();
            IDesignSurfaceExt2 isurf   = (IDesignSurfaceExt2)surface;

            //- 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);
        }
Esempio n. 2
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;
            }
        }
Esempio n. 3
0
 private IComponent CreateRootComponent(TabPage tpage, DesignSurfaceExt2 surface, Type controlType,
                                        Size controlSize)
 {
     try
     {
         var rootComponent = surface.CreateRootComponent(controlType, controlSize);
         this.tabControl1.SelectedIndex = tabControl1.TabPages.Count - 1;
         rootComponent.Site.Name        = _mgr.GetValidFormName();
         //- display the DesignSurface
         var view = surface.GetView();
         if (null == view)
         {
             return(null);
         }
         //- change some properties
         view.Text = rootComponent.Site.Name;
         view.Dock = DockStyle.Fill;
         //- Note these assignments
         view.Parent = tpage;
         //- finally enable the Drag&Drop on RootComponent
         ((DesignSurfaceExt2)surface).EnableDragandDrop();
         return(rootComponent);
     } //end_try
     catch (Exception ex)
     {
         Console.WriteLine(
             $@"{Name} CreateRootComponent() has generated errors during loading!Exception: {ex.Message}");
         throw;
     } //end_catch
 }
Esempio n. 4
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;
        }
Esempio n. 5
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);
        }
Esempio n. 7
0
 public void DeleteDesignSurfaceExt2(DesignSurfaceExt2 item)
 {
     DesignSurfaceExt2Collection.Remove(item);
     try
     {
         item.Dispose();
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine(ex.Message);
     }
     var currentIndex = DesignSurfaceExt2Collection.Count - 1;
     ActiveDesignSurface = currentIndex >= 0 ? DesignSurfaceExt2Collection[currentIndex] : null;
 }
Esempio n. 8
0
        public void RemoveDesignSurface(DesignSurfaceExt2 surfaceToErase)
        {
            try {
                //- remove the TabPage which has the same name of
                //- the RootComponent host by DesignSurface "surfaceToErase"
                //- Note:
                //-     DesignSurfaceManager continues to reference the DesignSurface erased
                //-     that Designsurface continue to exist but it is no more reachable
                //-     this fact is usefull when generate new names for Designsurfaces just created
                //-     avoiding name clashing
                string  dsRootComponentName = surfaceToErase.GetIDesignerHost().RootComponent.Site.Name;
                TabPage tpToRemove          = null;
                foreach (TabPage tp in this.tbCtrlpDesigner.TabPages)
                {
                    if (tp.Name == dsRootComponentName)
                    {
                        tpToRemove = tp;
                        break;
                    } //end_if
                }     //end_foreach
                if (null != tpToRemove)
                {
                    this.tbCtrlpDesigner.TabPages.Remove(tpToRemove);
                }


                //- now remove the DesignSurface
                this.DesignSurfaceManager.DeleteDesignSurfaceExt2(surfaceToErase);


                //- finally the DesignSurfaceManager remove the DesignSurface
                //- AND set as active DesignSurface the last one
                //- therefore we set as active the last TabPage
                this.tbCtrlpDesigner.SelectedIndex = this.tbCtrlpDesigner.TabPages.Count - 1;
            }//end_try
            catch (Exception exx) {
                Debug.WriteLine(exx.Message);
                if (null != exx.InnerException)
                {
                    Debug.WriteLine(exx.InnerException.Message);
                }

                throw;
            }//end_catch
        }
Esempio n. 9
0
        private void newFormUseGridMenuItem_Click(object sender, EventArgs e)
        {
            //- step.0
            TabPage tp = CreateNewTabPage("Use Grid");
            //- step.1
            DesignSurfaceExt2 surface = CreateDesignSurface();

            //- step.2
            //- choose an alignment mode...
            ((DesignSurfaceExt2)surface).UseGridWithoutSnapping(new System.Drawing.Size(16, 16));
            //- step.3
            //- create the Root compoment, in these case a Form
            Control rootComponent         = (Control)CreateRootComponent(tp, surface, typeof(Form), new Size(600, 400));
            int     iTabPageSelectedIndex = this.tabControl1.SelectedIndex;

            rootComponent.Text      = "Root Component hosted by the DesignSurface N." + iTabPageSelectedIndex;
            rootComponent.BackColor = Color.LightGreen;
        }
Esempio n. 10
0
        private void newFormUseSnapLinesMenuItem_Click(object sender, EventArgs e)
        {
            //- step.0
            TabPage tp = CreateNewTabPage("Use SnapLines");
            //- step.1
            DesignSurfaceExt2 surface = CreateDesignSurface();

            //- step.2
            //- choose an alignment mode...
            ((DesignSurfaceExt2)surface).UseSnapLines();
            //- step.3
            //- create the Root compoment, in these case a Form
            Control rootComponent         = (Control)CreateRootComponent(tp, surface, typeof(Form), new Size(400, 400));
            int     iTabPageSelectedIndex = this.tabControl1.SelectedIndex;

            rootComponent.Text      = "Root Component hosted by the DesignSurface N." + iTabPageSelectedIndex;
            rootComponent.BackColor = Color.Yellow;
        }
Esempio n. 11
0
        private void newFormAlignControlByhandMenuItem_Click(object sender, EventArgs e)
        {
            //- step.0
            TabPage tp = CreateNewTabPage("Align control by hand");
            //- step.1
            DesignSurfaceExt2 surface = CreateDesignSurface();

            //- step.2
            //- choose an alignment mode...
            ((DesignSurfaceExt2)surface).UseNoGuides();
            //- step.3
            //- create the Root compoment, in these case a Form
            Control rootComponent         = (Control)CreateRootComponent(tp, surface, typeof(Form), new Size(640, 480));
            int     iTabPageSelectedIndex = this.tabControl1.SelectedIndex;

            rootComponent.Text      = "Root Component hosted by the DesignSurface N." + iTabPageSelectedIndex;
            rootComponent.BackColor = Color.LightGray;
        }
Esempio n. 12
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);
     };
 }
        public void DeleteDesignSurfaceExt2(int index)
        {
            DesignSurfaceExt2 item = DesignSurfaceExt2Collection[index];

            DesignSurfaceExt2Collection.RemoveAt(index);
            try {
                item.Dispose();
            }
            catch (Exception ex) {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
            int currentIndex = DesignSurfaceExt2Collection.Count - 1;

            if (currentIndex >= 0)
            {
                ActiveDesignSurface = DesignSurfaceExt2Collection[currentIndex];
            }
            else
            {
                ActiveDesignSurface = null;
            }
        }
Esempio n. 14
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);
            }
        }
        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);
        }
Esempio n. 16
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);
        }
Esempio n. 17
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);
        }