public void OpenDocument(Document doc) { var newDoc = (TextDocument)doc; sci.AttachDocument(newDoc.GetSciDocument()); try { sci.Select(); } catch { } sci.FistVisibleLine = newDoc.FirstVisibleLine; if (newDoc.Selections != null) { foreach (var s in newDoc.Selections) { sci.AddSelection(s.End, s.Start, s.Main); } } OnDocumentOpened((T)doc); }