protected void textBox_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { if (e.Modifiers == Keys.Control) { //if (e.KeyCode == Keys.Z) //{ Undoer undoer = null; foreach (var x in dictionary) { if (x.Key.Equals(tabFiles.SelectedTab.Controls[1])) { undoer = x.Value; } } undoer.UndoWords(); e.Handled = true; } if (e.KeyCode == Keys.Escape) { Undoer undoer = null; foreach (var x in dictionary) { if (x.Key.Equals(tabFiles.SelectedTab.Controls[1])) { undoer = x.Value; } } undoer.RedoWords(); e.Handled = true; } }
public Form1() { InitializeComponent(); files = new Dictionary <string, TabPage>(); files.Add("New", tabItem); richTextBox1.TextChanged += new EventHandler(TextBoxTextChanged); Undoer undoer = new Undoer(richTextBox1); dictionary[richTextBox1] = undoer; // create a context menu menu = new ContextMenu(); menu.MenuItems.AddRange(new MenuItem[] { new MenuItem("&UndoWords", new EventHandler(undoer.undoWord_Click)), new MenuItem("&RedoWords", new EventHandler(undoer.redoWord_Click)), new MenuItem("&UndoLetters", new EventHandler(undoer.undoLetter_Click)), new MenuItem("&RedoLetters", new EventHandler(undoer.redoLetter_Click)), }); this.richTextBox1.ContextMenu = menu; richTextBox1.ShortcutsEnabled = false; // or create keypress event //this.richTextBox1.KeyDown += new KeyEventHandler(textBox_KeyDown); //this.KeyDown += new KeyEventHandler(textBox_KeyDown); richTextBox1.KeyDown += textBox_KeyDown; }
private void richTextBox1_KeyPress(object sender, KeyPressEventArgs e) { if (e.Equals(Keys.Z)) { Undoer undoer = null; foreach (var x in dictionary) { if (x.Key.Equals(tabFiles.SelectedTab.Controls[1])) { undoer = x.Value; } } undoer.UndoWords(); e.Handled = true; } if (e.Equals(Keys.Y)) { Undoer undoer = null; foreach (var x in dictionary) { if (x.Key.Equals(tabFiles.SelectedTab.Controls[1])) { undoer = x.Value; } } undoer.RedoWords(); e.Handled = true; } }
private void richTextBox1_KeyDown(object sender, KeyEventArgs e) { if (e.Modifiers == (System.Windows.Forms.Keys.Control)) { if (e.KeyCode == Keys.Z) { Undoer undoer = null; foreach (var x in dictionary) { if (x.Key.Equals(tabFiles.SelectedTab.Controls[1])) { undoer = x.Value; } } undoer.UndoWords(); e.Handled = true; } if (e.KeyCode == Keys.Y) { Undoer undoer = null; foreach (var x in dictionary) { if (x.Key.Equals(tabFiles.SelectedTab.Controls[1])) { undoer = x.Value; } } undoer.RedoWords(); e.Handled = true; } } }
protected void TextBoxTextChanged(object sender, EventArgs e) { Undoer u = null; foreach (var x in dictionary) { if (x.Key.Equals(tabFiles.SelectedTab.Controls[1])) { u = x.Value; } } u.Save(); }
private void newToolStripMenuItem_Click(object sender, EventArgs e) { int index = 1; List <string> keys = new List <string>(); foreach (string key in files.Keys) { if (key.StartsWith("New")) { keys.Add(key); } } if (keys.Count == 0) { index = 0; } else if (keys.Count == 1) { index = 1; } else { keys.Sort(); index = 1; 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++; } } } tabNumber++; TabPage first = tabFiles.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 = rtb2; lineTextBox = rtb; rtb2.ShortcutsEnabled = false; rtb2.ScrollBars = 0; rtb2.Click += richTextBox1_ClickTabs; rtb2.FontChanged += richTextBox1_FontChangedTabs; rtb2.SelectionChanged += richTextBox1_SelectionChangedTabs; rtb2.TextChanged += richTextBox1_TextChangedTabs; rtb2.KeyDown += textBox_KeyDown; rtb2.VScroll += richTextBox1_VScrollTabs; rtb2.TextChanged += TextBoxTextChanged; page.Controls.Add(rtb); page.Controls.Add(rtb2); Undoer undoer = new Undoer(rtb2); dictionary[rtb2] = undoer; menu = new ContextMenu(); menu.MenuItems.AddRange(new MenuItem[] { new MenuItem("&UndoWords", new EventHandler(undoer.undoWord_Click)), new MenuItem("&RedoWords", new EventHandler(undoer.redoWord_Click)), new MenuItem("&UndoLetters", new EventHandler(undoer.undoLetter_Click)), new MenuItem("&RedoLetters", new EventHandler(undoer.redoLetter_Click)), }); rtb2.ContextMenu = menu; string title = index == 0 ? "New" : ("New " + index); page.Text = title; rtb.Text = ""; files[title] = page; tabFiles.TabPages.Add(page); tabFiles.SelectedTab = page; }