private void OpenFileMenuItem_Click(object sender, EventArgs e) { // Set limit for opened files. if (files.Count == 10) { MessageBox.Show("You can open no more than 10 files"); return; } OpenFileDialog open = new OpenFileDialog { Title = "Open File", Filter = "(*.txt)|*.txt|(*.rtf)|*.rtf|(*.cs)|*.cs|All files (*.txt;*.rtf;*.cs*)|*.txt;*.rtf;*.cs;", FilterIndex = 4 }; if (open.ShowDialog() == DialogResult.OK) { try { UpdateText(); MyFile file = new MyFile(open.FileName); files.Add(file); curFile = file; // Check for correct text assignment. if (curFile.wasRtf) { textEditorRichTextBox.Rtf = curFile.FileText; } else { textEditorRichTextBox.Text = curFile.FileText; } textEditorRichTextBox.Visible = true; AddTab(Path.GetFileName(curFile.FilePath)); filesTabControl.SelectedTab = curFile.Page; } catch (Exception exc) { MessageBox.Show(exc.Message); } } }
/// <summary> /// Loads tabs in tabControl. /// </summary> /// <param name="tabControl"> Where to load tabs. </param> /// <returns> List with opened files. </returns> public MyFileList SetTabControl(TabControl tabControl) { MyFileList files = new MyFileList(); foreach (var e in openedTabs) { files.Add(new MyFile(e)); } for (int i = 0; i < files.Count; i++) { tabControl.TabPages.Add(files[i].Page); } tabControl.SelectedIndex = CurTabId; return(files); }