/// <summary> /// InitDesigner /// </summary> /// <param name="formId"></param> /// <param name="version"></param> void InitDesigner(int formId, int version) { if (this.isSelected) { return; } this.Loading = true; try { SuspendLayoutUc(); this.Cursor = Cursors.WaitCursor; designSurface = new DesignSurface(); this.pnlDesignPanel.Controls.Clear(); //服务容器 IServiceContainer serviceContainer = designSurface.GetService(typeof(IServiceContainer)) as IServiceContainer; idh = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost)); _KeyStrokeMessageFilter.SetHostAndMDIForm(idh, designSurface); //工具箱服务 this.toolboxServiceXtraTree.host = idh; serviceContainer.AddService(typeof(IToolboxService), this.toolboxServiceXtraTree); PopulateToolbox(this.toolboxServiceXtraTree); this.toolboxServiceXtraTree.designPanel = this.pnlDesignPanel; //菜单命令服务 menuService = new MenuCommandServiceImpl(serviceContainer); serviceContainer.AddService(typeof(IMenuCommandService), menuService); //命名服务 serviceContainer.AddService(typeof(INameCreationService), new NameCreationService(idh)); //控件序列化反序列化服务 serviceContainer.AddService(typeof(IDesignerSerializationService), new DesignerSerializationServiceForm(idh)); //获取控件信息 EntityFormDesign formVo = new EntityFormDesign(); if (formId > 0) { this.IsExists = true; ProxyFormDesign proxy = new ProxyFormDesign(); proxy.Service.GetForm(formId, version, out formVo); proxy = null; this.PrintTemplateId = formVo.Printtemplateid; } if (formVo != null && formVo.Formid > 0) { SetMainInfo(formVo); if (!string.IsNullOrEmpty(formVo.Layout)) { formCtrlData = FormTool.Entities(formVo.Layout); } } else { this.cboEfStatus.SelectedIndex = 1; this.pnlDesignPanel.Height = this.Height - 80; } if ((this.FormType > 2 && formId <= 0 && (formVo == null || string.IsNullOrEmpty(formVo.Layout)))) { this.txtEfCode.Properties.ReadOnly = true; this.txtEfName.Properties.ReadOnly = true; } if (this.FormType > 2) { this.cboVersion.Text = "1"; this.cboVersion.Properties.ReadOnly = true; this.cboEfStatus.SelectedIndex = 1; this.cboEfStatus.Properties.ReadOnly = true; } if (this.FormType > 10) { this.txtEfCode.Properties.ReadOnly = true; this.txtEfName.Properties.ReadOnly = true; this.cboVersion.Text = "1"; this.cboVersion.Properties.ReadOnly = true; this.cboEfStatus.SelectedIndex = 1; this.cboEfStatus.Properties.ReadOnly = true; } //if (this.TemplateMainVo != null) //{ // this.txtEfCode.Text = this.TemplateMainVo.templateCode; // this.txtEfName.Text = this.TemplateMainVo.templateName; //} if (this.txtEfCode.Text.Trim() == string.Empty) { this.txtEfCode.Text = DateTime.Now.ToString("yyMMddHHmm"); } loader = new DesignLoaderForm(idh, formCtrlData); loader.InitWidth = this.pnlDesignPanel.Width - 30; loader.InitHeight = this.pnlDesignPanel.Height - 30; loader.FormFlag = true; //绑定事件 loader.ComponentAdded -= new ComponentEventHandler(loader_ComponentAdded); loader.ComponentAdded += new ComponentEventHandler(loader_ComponentAdded); loader.ComponentChanged -= new ComponentChangedEventHandler(loader_ComponentChanged); loader.ComponentChanged += new ComponentChangedEventHandler(loader_ComponentChanged); loader.ComponentRemoved -= new ComponentEventHandler(loader_ComponentRemoved); loader.ComponentRemoved += new ComponentEventHandler(loader_ComponentRemoved); designSurface.BeginLoad(loader); Control ctrl = designSurface.View as Control; ctrl.Parent = pnlDesignPanel; ctrl.Dock = DockStyle.Fill; ISelectionService selectionService = designSurface.GetService(typeof(ISelectionService)) as ISelectionService; selectionService.SelectionChanged -= new EventHandler(selectionService_SelectionChanged); selectionService.SelectionChanged += new EventHandler(selectionService_SelectionChanged); BehaviorService bhsvc = idh.GetService(typeof(BehaviorService)) as BehaviorService; //undo/redo服务 serializationService = new ComponentSerializationServiceImpl(idh); serviceContainer.AddService(typeof(ComponentSerializationService), serializationService); undoEngine = new UndoEngineImpl(idh); serviceContainer.AddService(typeof(UndoEngine), undoEngine); } catch (Exception ex) { throw ex; } finally { ResumeLayoutUc(); Loading = false; this.Cursor = Cursors.Default; } }