public void OpenNote(string a_filePath, string a_fileName, string a_course) { // Check to see if note is already open foreach (TabPage page in mainTabControl.TabPages) { if (page.Text == string.Format("[{0}] {1}", a_course, a_fileName)) { mainTabControl.SelectedTab = page; return; } } CustomRichTextBox newBox = new CustomRichTextBox(); newBox.Font = new Font(newBox.Font.FontFamily, 10.5f, FontStyle.Regular); newBox.LoadFile(a_filePath); newBox.Size = template_rtb.Size; newBox.Location = template_rtb.Location; newBox.HideSelection = false; newBox.ReadOnly = true; // Create new tab, make sure all TabPage values are srt to null CustomTab newTab = new CustomTab("", "", "", null); newTab.Text = string.Format("[{0}] {1}", a_course, a_fileName); newTab.Controls.Add(newBox); mainTabControl.TabPages.Add(newTab); ResizeTabControlAndChildren(); }
private void OpenTab(string a_path = "NULL") { CustomRichTextBox newBox = new CustomRichTextBox(); newBox.OnLineNumberChanged += Event_OnActiveTextBoxLineChanged; newBox.Font = new Font(newBox.Font.FontFamily, 10.5f, FontStyle.Regular); newBox.Size = template_rtb.Size; newBox.Location = template_rtb.Location; newBox.HideSelection = false; if (a_path == "NULL") { using (NewTabDetailsForm form = new NewTabDetailsForm(mLoadedSemesters.ToArray())) { DialogResult result = form.ShowDialog(); if (result == DialogResult.OK) { // Create new tab, make sure all TabPage values are set to null CustomTab newTab = new CustomTab(form.Semester, form.Course, form.ClassType, MainNoteDirectory + form.Semester + "\\" + form.Course + "\\Notes\\" + string.Format("{0}-{1}-{2}_{3}.rtf", DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, form.ClassType)); newTab.Text = string.Format("[{0}] {1}", form.Course, string.Format("{0}-{1}-{2}_{3}.rtf", DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, form.ClassType)); newTab.Controls.Add(newBox); mainTabControl.TabPages.Add(newTab); mainTabControl.SelectedIndex = mainTabControl.TabPages.Count - 1; // If the tab that was just added is the only tab (TabPages.Count == 1) if (mainTabControl.TabPages.Count == 1) { foreach (Control ctrl in mainTabControl.SelectedTab.Controls) { if (ctrl.GetType() == typeof(CustomRichTextBox)) { activeRichTextBox = (CustomRichTextBox)ctrl; CustomConsole.Log("Set the child of CustomTab with id: " + ((CustomTab)mainTabControl.SelectedTab).mTabId + " to the active CustomRichTextBox"); } } } } } } else { string[] splitFileName = a_path.Split('\\'); string temp_semester = splitFileName[splitFileName.Length - 4]; string[] classTypeSplit = splitFileName[splitFileName.Length - 1].Split('_'); string temp_classtype = classTypeSplit[1].Split('.')[0]; string temp_course = splitFileName[splitFileName.Length - 3]; newBox.LoadFile(a_path); // Create new tab, make sure all TabPage values are srt to null CustomTab newTab = new CustomTab(temp_semester, temp_course, temp_classtype, a_path); newTab.Text = string.Format("[{0}] {1}", temp_course, splitFileName[splitFileName.Length - 1]); newTab.Controls.Add(newBox); mainTabControl.TabPages.Add(newTab); CustomConsole.Log("Opened file to edit: " + a_path); // If the tab that was just added is the only tab (TabPages.Count == 1) if (mainTabControl.TabPages.Count == 1) { foreach (Control ctrl in mainTabControl.SelectedTab.Controls) { if (ctrl.GetType() == typeof(CustomRichTextBox)) { activeRichTextBox = (CustomRichTextBox)ctrl; CustomConsole.Log("Set the child of CustomTab with id: " + ((CustomTab)mainTabControl.SelectedTab).mTabId + " to the active CustomRichTextBox"); } } } } }