public FormsDesignerContent(FormsDesignerExtension parent, OpenedFile sourceFile) : base(parent) { _language = (NetLanguageDescriptor)LanguageDescriptor.GetLanguageByPath(sourceFile.FilePath); if (!(_language is NetLanguageDescriptor)) { throw new ArgumentException("File must be a .NET source file."); } _extensionHost = parent.ExtensionHost; _extensionHost.ControlManager.AppearanceChanged += ControlManager_AppearanceChanged; _propertyContainer = new PropertyContainer(); _serviceContainer = new ServiceContainer(); _surfaceManager = parent.DesignerSurfaceManager; _codeReader = new DesignerCodeReader(_extensionHost, _language); _codeWriter = new DesignerCodeWriter(_language); this.Text = sourceFile.FilePath.FileName + sourceFile.FilePath.Extension + " [Design]"; this.AssociatedFile = sourceFile; this.AssociatedFile.FilePathChanged += AssociatedFile_FilePathChanged; _errorControl = new ErrorControl() { Dock = DockStyle.Fill, }; _errorControl.ReloadRequested += _errorControl_ReloadRequested; SetupDesigner(); }
/// <summary> /// Parses a source code and creates a new design surface. /// </summary> /// <param name="serviceContainer"></param> /// <param name="surfaceManager"></param> /// <param name="file">The source file to deserialize.</param> /// <returns></returns> public DesignSurface Deserialize(DesignSurfaceManager surfaceManager, IServiceContainer serviceContainer, OpenedFile file) { DesignSurface surface = surfaceManager.CreateDesignSurface(serviceContainer); IDesignerHost designerHost = surface.GetService(typeof(IDesignerHost)) as IDesignerHost; Type componentType = CompileTypeFromFile(file); // load base type. surface.BeginLoad(componentType.BaseType); // get instance to copy components and properties from. Control instance = Activator.CreateInstance(componentType) as Control; // add components var components = CreateComponents(componentType, instance, designerHost); InitializeComponents(components, designerHost); Control rootControl = designerHost.RootComponent as Control; Control parent = rootControl.Parent; ISite site = rootControl.Site; // copy instance properties to root control. CopyProperties(instance, designerHost.RootComponent); rootControl.AllowDrop = true; rootControl.Parent = parent; rootControl.Visible = true; rootControl.Site = site; designerHost.RootComponent.Site.Name = instance.Name; return(surface); }
private void OnIdle(object sender, EventArgs e) { Application.Idle -= new EventHandler(this.OnIdle); if (this._state[StateReloadAtIdle]) { this._state[StateReloadAtIdle] = false; DesignSurfaceManager service = (DesignSurfaceManager)this.GetService(typeof(DesignSurfaceManager)); DesignSurface objB = (DesignSurface)this.GetService(typeof(DesignSurface)); if (((service != null) && (objB != null)) && !object.ReferenceEquals(service.ActiveDesignSurface, objB)) { this._state[StateActiveDocument] = false; this._state[StateDeferredReload] = true; } else { IDesignerLoaderHost loaderHost = this.LoaderHost; if ((loaderHost != null) && (this._state[StateForceReload] || this.IsReloadNeeded())) { try { if (this._state[StateFlushReload]) { this.Flush(); } this.UnloadDocument(); loaderHost.Reload(); } finally { this._state[(StateForceReload | StateModifyIfErrors) | StateFlushReload] = false; } } } } }
private void InitializeSurface() { DesignSurface surface = new DesignSurfaceManager().CreateDesignSurface(); surface.BeginLoad(typeof(MyForm)); this._panelDesignerView.Controls.Add((Control)surface.View); ((Control)surface.View).Dock = DockStyle.Fill; this.serviceContainer = surface.GetService(typeof(IServiceContainer)) as IServiceContainer; serviceContainer.AddService(typeof(IToolboxService), _toolbox); ISelectionService s = (ISelectionService)serviceContainer.GetService(typeof(ISelectionService)); s.SelectionChanged += new EventHandler(OnSelectionChanged); PopulateToolbox(_toolbox); }
public ComponentDesigner(Type componentType) { originalComponentType = componentType; surfaceManager = new DesignSurfaceManager(); surface = surfaceManager.CreateDesignSurface(); surface.BeginLoad(componentType); this._serviceProvider = surface; componentInDesign = DesignerHost.RootComponent; NameCreationService _nameCreationService = new NameCreationService(); if (_nameCreationService != null) { this.DesignerHost.RemoveService(typeof(INameCreationService), false); this.DesignerHost.AddService(typeof(INameCreationService), _nameCreationService); } try { MethodInfo m = componentInDesign.GetType().GetMethod(InvokeInitMethod); if (m != null) { m.Invoke(componentInDesign, new object[] { }); } } catch (Exception e) { MessageBox.Show(e.Message); } }
public FormsDesignerExtension() { _formEditors = new Dictionary <OpenedFile, FormsDesignerContent>(); ToolBoxBuilder = new FormsToolBoxBuilder(); DesignerSurfaceManager = new DesignSurfaceManager(); }
//public void ParseComponentChanged() ////{ //// 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(this.DesignSurfaceManager.ActiveDesignSurface); //// }; //// //System.ComponentModel.Design.DesignerActionUIStateChangeEventHandler //// componentChangeService.ComponentChanging += (Object sender, ComponentChangingEventArgs e) => //// { //// DesignSurfaceManager.UpdatePropertyGridHost(this.DesignSurfaceManager.ActiveDesignSurface); //// }; //// componentChangeService.ComponentAdded += (Object sender, ComponentEventArgs e) => //// { //// DesignSurfaceManager.UpdatePropertyGridHost(this.DesignSurfaceManager.ActiveDesignSurface); //// }; //// componentChangeService.ComponentRemoved += (Object sender, ComponentEventArgs e) => //// { //// DesignSurfaceManager.UpdatePropertyGridHost(this.DesignSurfaceManager.ActiveDesignSurface); //// }; //// } //} void p_MouseUp(object sender, MouseEventArgs e) { DesignSurfaceManager.UpdatePropertyGridHost(DesignSurfaceManager.ActiveDesignSurface); }
public void ChangeXLocationOfControls(bool isRight) { DesignSurfaceManager.UpdateXLocationPropertyGridHost(isRight); }
//- 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); }
//- 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); }
private void InitializeSurface () { DesignSurface surface = new DesignSurfaceManager ().CreateDesignSurface (); surface.BeginLoad (typeof (MyForm)); this._panelDesignerView.Controls.Add ((Control)surface.View); ((Control)surface.View).Dock = DockStyle.Fill; this.serviceContainer = surface.GetService (typeof (IServiceContainer)) as IServiceContainer; serviceContainer.AddService (typeof (IToolboxService), _toolbox); ISelectionService s = (ISelectionService)serviceContainer.GetService (typeof (ISelectionService)); s.SelectionChanged += new EventHandler (OnSelectionChanged); PopulateToolbox (_toolbox); }
//- 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); }
public KeystrokeMessageFilter(DesignSurfaceManager manager) { surfaceMan = manager; }
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); }