private void btbFind_Click(object sender, EventArgs e) { if (!(this.cmbFind.Text == string.Empty)) { FrmMain frmMain = (FrmMain)this.Owner; if (frmMain.tsmTabbed.Checked) { foreach (Control control in frmMain.Controls) { try { TabControl tabControl = (TabControl)control; TabPage tabPage = tabControl.SelectedTab; CustomRichTextBox richTextBox = (CustomRichTextBox)tabPage.Controls[0]; this.searchInRichTextBox(richTextBox); } catch (InvalidCastException ex) { } } } else { Form activeForm = frmMain.ActiveMdiChild; CustomRichTextBox richTextBox = (CustomRichTextBox)activeForm.Controls[0]; this.searchInRichTextBox(richTextBox); } } }
private void tsmTabbed_Click(object sender, EventArgs e) { this.tsmWindow.Enabled = true; this.tsmWindow.Checked = false; this.tsmTabbed.Enabled = false; this.tsmTabbed.Checked = true; tcMain.Visible = true; foreach (Form form in this.MdiChildren) { foreach (Control control in form.Controls) { try { CustomRichTextBox richTextBox = (CustomRichTextBox)control; TabPage tabPage = new TabPage(); tabPage.Controls.Add(richTextBox); tcMain.TabPages.Add(tabPage); tabPage.Text = form.Text; } catch (InvalidCastException ex) { } } form.Dispose(); } tpPlus = new TabPage(); tpPlus.Text = "+"; tcMain.TabPages.Add(tpPlus); this.IsMdiContainer = false; }
private void tsmWindow_Click(object sender, EventArgs e) { this.tsmWindow.Enabled = false; this.tsmWindow.Checked = true; this.tsmTabbed.Enabled = true; this.tsmTabbed.Checked = false; this.IsMdiContainer = true; createSelectedTabForm(); foreach (TabPage tabPage in this.tcMain.TabPages) { if (tabPage.GetHashCode() != tcMain.SelectedTab.GetHashCode()) { foreach (Control control in tabPage.Controls) { try { CustomRichTextBox richTextBox = (CustomRichTextBox)control; Form form = new Form(); form.MdiParent = this; form.Controls.Add(richTextBox); form.Text = tabPage.Text; form.Show(); form.BringToFront(); } catch (InvalidCastException ex) { } } } } this.tcMain.Controls.Clear(); this.tcMain.Visible = false; }
private void createSelectedTabForm() { CustomRichTextBox richTextBox = (CustomRichTextBox)tcMain.SelectedTab.Controls[0]; Form form = new Form(); form.MdiParent = this; form.Controls.Add(richTextBox); form.Text = tcMain.SelectedTab.Text; form.Show(); }
private void tsmiSaveAs_Click(object sender, EventArgs e) { if (this.tsmTabbed.Checked) { SaveFileDialog saveFileDialog = new SaveFileDialog(); if (saveFileDialog.ShowDialog() == DialogResult.OK) { try { TabPage selectedTab = this.tcMain.SelectedTab; foreach (Control control in selectedTab.Controls) { try { CustomRichTextBox richTextBox = (CustomRichTextBox)control; System.IO.File.WriteAllText(saveFileDialog.FileName, richTextBox.Text); Model.Content content = richTextBox.Content; content.FileName = saveFileDialog.FileName; content.offDirtyBit(); this.Text = "MyOwnTextEditor - " + content.FileName; this.tcMain.SelectedTab.Text = content.FileName; richTextBox.Select(); } catch (InvalidCastException ex) { } } } catch (Exception exception) { MessageBox.Show("There was an error writing the file"); } } } else { SaveFileDialog saveFileDialog = new SaveFileDialog(); if (saveFileDialog.ShowDialog() == DialogResult.OK) { try { Form form = this.ActiveMdiChild; CustomRichTextBox richTextBox = (CustomRichTextBox)form.Controls[0]; System.IO.File.WriteAllText(saveFileDialog.FileName, richTextBox.Text); Model.Content content = richTextBox.Content; content.FileName = saveFileDialog.FileName; content.offDirtyBit(); this.Text = "MyOwnTextEditor - " + content.FileName; form.Text = content.FileName; richTextBox.Select(); } catch (NullReferenceException ex) { } } } }
private void open() { OpenFileDialog openFileDialog = new OpenFileDialog(); if (openFileDialog.ShowDialog() == DialogResult.OK) { try { if (this.tsmTabbed.Checked) { TabPage selectedTab = this.tcMain.SelectedTab; foreach (Control control in selectedTab.Controls) { try { CustomRichTextBox richTextBox = (CustomRichTextBox)control; richTextBox.Text = System.IO.File.ReadAllText(openFileDialog.FileName); Model.Content content = richTextBox.Content; content.FileName = openFileDialog.FileName; content.offDirtyBit(); this.Text = "MyOwnTextEditor - " + content.FileName; selectedTab.Text = content.FileName; richTextBox.Select(); } catch (InvalidCastException e) { } } } else { Form form = this.MdiChildren.Last(); try { CustomRichTextBox richTextBox = (CustomRichTextBox)form.Controls[0]; richTextBox.Text = System.IO.File.ReadAllText(openFileDialog.FileName); Model.Content content = richTextBox.Content; content.FileName = openFileDialog.FileName; content.offDirtyBit(); form.Text = content.FileName; richTextBox.Select(); } catch (InvalidCastException ex) { } } } catch (Exception exception) { MessageBox.Show("There was an error reading the file"); } } }
private void tsmiSave_Click(object sender, EventArgs e) { if (this.tsmTabbed.Checked) { if (customTextRichBoxes[tcMain.SelectedIndex].Content.FileName == String.Empty) { this.tsmiSaveAs_Click(sender, e); } else { TabPage selectedTab = this.tcMain.SelectedTab; foreach (Control control in selectedTab.Controls) { try { CustomRichTextBox richTextBox = (CustomRichTextBox)control; System.IO.File.WriteAllText(this.customTextRichBoxes[this.tcMain.SelectedIndex].Content.FileName, richTextBox.Text); Model.Content content = this.customTextRichBoxes[this.tcMain.SelectedIndex].Content; content.offDirtyBit(); selectedTab.Text = content.FileName; richTextBox.Select(); } catch (InvalidCastException ex) { } } } } else { try { Form form = this.ActiveMdiChild; CustomRichTextBox richTextBox = (CustomRichTextBox)form.Controls[0]; if (richTextBox.Content.FileName == String.Empty) { this.tsmiSaveAs_Click(sender, e); } else { System.IO.File.WriteAllText(richTextBox.Content.FileName, richTextBox.Text); Model.Content content = richTextBox.Content; content.offDirtyBit(); form.Text = content.FileName; richTextBox.Select(); } } catch (NullReferenceException ex) { } } }
private void newTabPage() { CustomRichTextBox richTextBox = new CustomRichTextBox(new Model.Content()); TabPage tabPage = new TabPage("new File"); this.tcMain.TabPages.Insert(this.tcMain.TabPages.Count - 1, tabPage); tabPage.Controls.Add(richTextBox); richTextBox.Dock = DockStyle.Fill; richTextBox.TextChanged += this.rtbTextChanged; this.tcMain.SelectedTab = tabPage; this.customTextRichBoxes.Add(richTextBox); richTextBox.Select(); }
private void newChildForm() { CustomRichTextBox richTextBox = new CustomRichTextBox(new Model.Content()); richTextBox.Dock = DockStyle.Fill; richTextBox.TextChanged += this.rtbTextChanged; Form form = new Form(); form.MdiParent = this; form.Controls.Add(richTextBox); form.Show(); this.customTextRichBoxes.Add(richTextBox); richTextBox.Select(); }
private void searchInRichTextBox(CustomRichTextBox richTextBox) { richTextBox.TextChanged -= ((FrmMain)this.Owner).rtbTextChanged; string text = richTextBox.Text; richTextBox.Clear(); richTextBox.Text = text; startIndex = richTextBox.Text.IndexOf(cmbFind.Text, startIndex + 1); if (startIndex != -1) { richTextBox.Select(startIndex, cmbFind.Text.Length); richTextBox.SelectionColor = System.Drawing.Color.White; richTextBox.SelectionBackColor = System.Drawing.Color.Blue; richTextBox.TextChanged += ((FrmMain)this.Owner).rtbTextChanged; } }
public void rtbTextChanged(object sender, EventArgs e) { if (this.tsmTabbed.Checked) { if (!this.customTextRichBoxes[this.tcMain.SelectedIndex].Content.DirtyBit) { this.customTextRichBoxes[this.tcMain.SelectedIndex].Content.onDirtyBit(); this.tcMain.SelectedTab.Text = this.tcMain.SelectedTab.Text + '*'; } } else { CustomRichTextBox richTextBox = (CustomRichTextBox)sender; if (!richTextBox.Content.DirtyBit) { richTextBox.Content.onDirtyBit(); richTextBox.Parent.Text = richTextBox.Parent.Text + '*'; } } }
public FrmMain() { Thread.CurrentThread.CurrentCulture = new CultureInfo("es-ES"); // Sets the UI culture to French (France) Thread.CurrentThread.CurrentUICulture = new CultureInfo("es-ES"); InitializeComponent(); customTextRichBoxes = new List <CustomRichTextBox>(); CustomRichTextBox richTextBox = new CustomRichTextBox(new Model.Content()); richTextBox.Dock = DockStyle.Fill; tp1.Controls.Add(richTextBox); richTextBox.TextChanged += this.rtbTextChanged; this.tcMain.SelectedTab = tp1; this.customTextRichBoxes.Add(richTextBox); richTextBox.Select(); }