private DesignSurfaceExt2 CreateDesignSurface() { //- step.0 //- create a DesignSurface and put it inside a Form in DesignTime DesignSurfaceExt2 surface = new DesignSurfaceExt2(); //- //- IDesignSurfaceExt2 isurf = (IDesignSurfaceExt2)surface; this._listOfDesignSurface.Add(isurf); //- 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); }
private void newFormUseSnapLinesMenuItem_Click(object sender, EventArgs e) { TabPage tp = new TabPage("Use SnapLines"); this.tabControl1.TabPages.Add(tp); int iTabPageSelectedIndex = this.tabControl1.SelectedIndex; //- steps.1.2.3 DesignSurfaceExt2 surface = CreateDesignSurface(); //- step.4 //- choose an alignment mode... ((DesignSurfaceExt2)surface).UseSnapLines(); //- step.5 //- create the Root compoment, in these cases a Form try { Form rootComponent = null; rootComponent = (Form)surface.CreateRootComponent(typeof(Form), new Size(400, 400)); rootComponent.Text = "Root Component hosted by the DesignSurface N." + iTabPageSelectedIndex; rootComponent.BackColor = Color.Yellow; //- //- //- step.4 //- display the DesignSurface Control view = surface.GetView(); if (null == view) { return; } //- change some properties view.Text = "Test Form N. " + iTabPageSelectedIndex; view.Dock = DockStyle.Fill; //- Note these assignments view.Parent = tp; //- finally enable the Drag&Drop on RootComponent ((DesignSurfaceExt2)surface).EnableDragandDrop(); }//end_try catch (Exception ex) { Console.WriteLine(Name + " the DesignSurface N. " + iTabPageSelectedIndex + " has generated errors during loading!Exception: " + ex.Message); return; }//end_catch }