private void TxtArea_TextChanged_1(object sender, EventArgs e) { if (txtArea.Text == "") { AddLineNumbers(); } UndoRedoStack u = null; foreach (var x in undoRedo) { if (x.Key.Equals(tabControl.SelectedTab.Controls[0])) { u = x.Value; } } var tab = tabControl.SelectedTab.Controls[0] as RichTextBox; int y = tab.SelectionStart; u.InsertText(tab.Text, y); }
private void NewFileToolStripMenuItem_Click(object sender, EventArgs e) { // txtArea.Text = ""; int index = 3; List <string> keys = new List <string>(); foreach (string key in files.Keys) { if (key.StartsWith("New")) { keys.Add(key); } } if (keys.Count == 0) { index = 2; } else if (keys.Count == 1) { index = 3; } else { keys.Sort(); index = 3; foreach (string s in keys) { string resultString = Regex.Match(s, @"\d+").Value; if (resultString.Length == 0) { continue; } int val = Int32.Parse(resultString); if (val > index) { break; } else if (val == index) { index++; } } } TabPage first = tabControl.TabPages[0]; RichTextBox txt = first.Controls[0] as RichTextBox; RichTextBox txt2 = first.Controls[1] as RichTextBox; TabPage page = new TabPage(); RichTextBox rtb = new RichTextBox(); RichTextBox rtb2 = new RichTextBox(); page.Bounds = first.Bounds; rtb.Bounds = txt.Bounds; rtb2.Bounds = txt2.Bounds; richtextbox = rtb; linetextbox = rtb2; rtb2.ScrollBars = 0; rtb.ShortcutsEnabled = false; rtb.FontChanged += TxtArea_FontChangedTabs; rtb.SelectionChanged += TxtArea_SelectionChangedTabs; rtb.TextChanged += TxtArea_TextChanged_1; rtb.MouseUp += ContextTabs; rtb.VScroll += TxtArea_VScrollTabs; page.Controls.Add(rtb); page.Controls.Add(rtb2); UndoRedoStack undoer = new UndoRedoStack(rtb); undoRedo[rtb] = undoer; string title = index == 0 ? "New" + index : ("New " + index); page.Text = title; rtb.Text = ""; files[title] = page; tabControl.TabPages.Add(page); tabControl.SelectedTab = page; rtbTab = rtb; rtb.Font = new Font("Courier new", 10); }
private void Form1_KeyUp(object sender, KeyEventArgs e) { if (e.KeyData == (Keys.Control | Keys.C)) { CopyToolStripMenuItem1_Click(null, null); } else if (e.KeyData == (Keys.Control | Keys.V)) { PasteToolStripMenuItem1_Click(null, null); } else if (e.KeyData == (Keys.Control | Keys.U)) { CutToolStripMenuItem1_Click(null, null); } else if (e.KeyData == (Keys.Control | Keys.D)) { DeleteToolStripMenuItem_Click(null, null); } else if (e.KeyData == (Keys.Control | Keys.A)) { SelectAllToolStripMenuItem1_Click(null, null); } else if (e.KeyData == (Keys.Control | Keys.Z)) { UndoRedoStack u = null; foreach (var x in undoRedo) { if (x.Key.Equals(tabControl.SelectedTab.Controls[0])) { u = x.Value; } } u.Undo(); } else if (e.KeyData == (Keys.Control | Keys.Y)) { UndoRedoStack u = null; foreach (var x in undoRedo) { if (x.Key.Equals(tabControl.SelectedTab.Controls[0])) { u = x.Value; } } u.Redo(); } if (txtArea.Focused) { int index = txtArea.SelectionStart; int line = txtArea.GetLineFromCharIndex(index); int firstChar = txtArea.GetFirstCharIndexFromLine(line); int column = index - firstChar; if (txtArea.Focused == true) { label2.Visible = false; } label1.Text = "Line : " + line + " Column : " + column; } else if (rtbTab.Focused) { int index2 = rtbTab.SelectionStart; int line2 = rtbTab.GetLineFromCharIndex(index2); int firstChar2 = rtbTab.GetFirstCharIndexFromLine(line2); int column2 = index2 - firstChar2; if (rtbTab.Focused == true) { label1.Visible = false; label2.Visible = true; } label2.Text = "Line : " + line2 + " Column : " + column2; } }