public void AddExistingFile() { using (OpenFileDialog d = new OpenFileDialog()) { d.Filter = "C# File|*.cs|Sketchbook Project|*.sbp"; d.Title = "Open File"; if (d.ShowDialog() == DialogResult.OK) { EditorForm form = GetActiveWindow() as EditorForm; if (form == null || form.Editor.Modified || !string.IsNullOrEmpty(form.EditorText)) { form = NewSourceFile(true); } using (TextReader reader = new StreamReader(d.OpenFile())) { form.FileName = d.FileName; form.Editor.Text = reader.ReadToEnd(); form.Editor.SetSavePoint(); reader.Close(); } form.Activate(); } } }
public EditorForm NewSourceFile(bool isOpeningFile) { EditorForm form = new EditorForm(); form.MdiParent = this; form.FormBorderStyle = FormBorderStyle.None; form.ControlBox = false; form.Show(); form.WindowState = FormWindowState.Maximized; form.TextChanged += MdiChildTextChanged; if (!isOpeningFile) { NewFileCounter++; form.Text = "New Sketch " + NewFileCounter; } tabWindows.TabButtons.Add(new TabButton() { Text = form.Text, Tag = form }); form.Activate(); return(form); }