private void OpenFiles(string[] fns, string caption) { // Open file(s) foreach (string fn in fns) { FrmDocument dummyDoc = new FrmDocument(); ; TextEditorControl editor = new TextEditorControl(); try { if (dockPanel.DocumentStyle == DocumentStyle.SystemMdi) { dummyDoc = CreateNewDocument(Path.GetFileName(fn)); dummyDoc.MdiParent = this; dummyDoc.Show(); } else { foreach (IDockContent content in dockPanel.Documents) { dummyDoc = content as FrmDocument; if (dummyDoc != null) { editor = dummyDoc.Controls[0] as TextEditorControl; if (editor.FileName == fn) { content.DockHandler.Show(); return; } } } dummyDoc = CreateNewDocument(Path.GetFileName(fn)); editor = dummyDoc.Controls[0] as TextEditorControl; editor.LoadFile(fn); editor.Document.DocumentChanged += new DocumentEventHandler(Document_DocumentChanged); // Modified flag is set during loading because the document // "changes" (from nothing to something). So, clear it again. SetModifiedFlag(editor, false); if (!String.IsNullOrEmpty(caption)) dummyDoc.Text = caption; dummyDoc.LastWriteTime = new FileInfo(fn).LastWriteTime; dummyDoc.Show(dockPanel); } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().Name); dummyDoc.Close(); dummyDoc.Dispose(); return; } // ICSharpCode.TextEditor doesn't have any built-in code folding // strategies, so I've included a simple one. Apparently, the // foldings are not updated automatically, so in this demo the user // cannot add or remove folding regions after loading the file. editor.Document.FoldingManager.FoldingStrategy = new RegionFoldingStrategy(); editor.Document.FoldingManager.UpdateFoldings(null, null); } }