private void mnuFile_Open_Click(object sender, EventArgs e) { //Show the open dialog var res = dlgOpen.ShowDialog(this); //Bail out if cancel was pressed or no file was selected. if (res != DialogResult.OK || dlgOpen.FileName == "") { return; } var fileName = dlgOpen.FileName; // if already open, then activate it var alreadyOpen = MdiChildren.SingleOrDefault(x => ((EditForm)x).Doc.Path == fileName) as EditForm; if (alreadyOpen != null) { alreadyOpen.BringToFront(); return; } var fi = new FileInfo(fileName); var doc = new Document { Path = fileName, Title = fi.Name }; var syntax = Languages.GetLanguageFromFile(doc.Path); using (var sr = new StreamReader(fileName, Encoding.Default)) { var text = sr.ReadToEnd(); var ef = new EditForm(doc, text, syntax) { MdiParent = this }; ef.Show(); } }