private void CreateNewDocument() { pages = GolableInstance.PageList(); string text = string.Empty; AddPageDialog addPage = new AddPageDialog(); addPage.btnAdd.Click += (o, args) => { text = Regex.Replace(addPage.txtInput.Text, @"(?<!\\)\\f", "\f"); m_solutionExplorer.AddNode(text); addPage.Close(); }; addPage.ShowDialog(); addPage.txtInput.Select(); DesignWorkbench dummyDoc = new DesignWorkbench(text); ActivPage = pages[pages.Count - 1];//刚生成的页面作为活动页面 dummyDoc.Text = text; PropertyInit(); ActivPage.selectionService.SelectionChanged += new EventHandler(selectionService_SelectionChanged); ActivPage.componentChangeService.ComponentAdded += ComponentListChanged; ActivPage.componentChangeService.ComponentRemoved += ComponentListChanged; ActivPage.componentChangeService.ComponentRename += ComponentListChanged; ActivPage.host.TransactionClosed += new DesignerTransactionCloseEventHandler(TransactionClosed); ++GolableInstance.Pagecount; UpdateComboBox(); if (dockPanel.DocumentStyle == DocumentStyle.SystemMdi) { dummyDoc.MdiParent = this; dummyDoc.Show(); } else { dummyDoc.Show(dockPanel); } }
private void menuItemOpen_Click(object sender, System.EventArgs e) { OpenFileDialog openFile = new OpenFileDialog(); openFile.InitialDirectory = Application.ExecutablePath; openFile.Filter = "rtf files (*.rtf)|*.rtf|txt files (*.txt)|*.txt|All files (*.*)|*.*"; openFile.FilterIndex = 1; openFile.RestoreDirectory = true; if (openFile.ShowDialog() == DialogResult.OK) { string fullName = openFile.FileName; string fileName = Path.GetFileName(fullName); if (FindDocument(fileName) != null) { MessageBox.Show("该文档: " + fileName + " 已经打开"); return; } DesignWorkbench dummyDoc = new DesignWorkbench(fileName); dummyDoc.Text = fileName; if (dockPanel.DocumentStyle == DocumentStyle.SystemMdi) { dummyDoc.MdiParent = this; dummyDoc.Show(); } else { dummyDoc.Show(dockPanel); } try { dummyDoc.FileName = fullName; } catch (Exception exception) { dummyDoc.Close(); MessageBox.Show(exception.Message); } } }