//public void UseSnapLines() public void UseOptionService(Interface.AlignmentModeEnum option) { //UseNewOptionService(new DesignerOptionServiceSnapLines()); switch (option) { case Interface.AlignmentModeEnum.SnapLines: UseNewOptionService(new DesignerOptionServiceSnapLines()); break; case Interface.AlignmentModeEnum.Grid: UseNewOptionService(new DesignerOptionServiceGrid(new Size(8, 8))); break; //case AlignmentModeEnum.GridWithoutSnapping: // UseNewOptionService(new DesignerOptionServiceGridWithoutSnapping(new Size(4, 4))); // break; //case AlignmentModeEnum.NoGuides: // UseNewOptionService(new DesignerOptionServiceNoGuides()); // break; default: UseNewOptionService(new DesignerOptionServiceSnapLines()); break; } }
//- Create the DesignSurface and the rootComponent (a .NET Control) //- using IDesignSurfaceBase.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 DesignSurfaceUView AddDesignSurface <TT>(int width, int height, Interface.AlignmentModeEnum alignmentMode) where TT : Control { const string _signature_ = _name + @"::AddDesignSurface<>()"; if (!this) { throw new Exception(_signature_ + " - Exception: " + _name + " is not initialized! Please set the Property: IUDesigner::Toolbox before calling any methods!"); } //- step.0 //- create a DesignSurface DesignSurfaceUView surface = DesignSurfaceManager.CreateDesignSurfaceEx() as DesignSurfaceUView; this.DesignSurfaceManager.ActiveDesignSurface = surface; //- step.1 //- choose an alignment mode... surface.UseOptionService(alignmentMode); //- step.2 //- enable the UndoEngine (surface.GetService(typeof(UndoEngine)) as UndoEngine).Enabled = true; //- step.3 //- Select the service IToolboxService //- and hook it to our ListBox var tbox = surface.GetService(typeof(IToolboxService)) as ToolboxServiceImp; //- we don't check if Toolbox is null because the very first check: if(!this)... if (null != tbox) { tbox.CtrlToolbox = this.CtrlToolbox; } //- 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), DesignSurfaceManager.GetValidName(typeof(TT).Name), new Size(width, height)) 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.GetValidName(typeof(TT).Name); //- step.5 //- enable the Drag&Drop on RootComponent 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) if (!InitSurfaceText(surface, rootComponent, rootComponent.Site.Name + " (design mode)")) { return(null); } //- step.8 //- display the DesignSurface AddSurfaceToNewTabPage(surface, rootComponent.Site.Name); //- step.9 //- finally return the DesignSurface created to let it be modified again by user DesignSurfaceManager.UpdatePropertyGridHost(surface); return(surface); }