Here are just the code I decided to chat with:
string buffer = String.Empty; string buffer2 = String.Empty; public Form3() { InitializeComponent(); this.richTextBox1.KeyDown += new KeyEventHandler(richTextBox1_KeyDown); this.richTextBox1.TextChanged += new EventHandler(richTextBox1_TextChanged); } void richTextBox1_TextChanged(object sender, EventArgs e) { buffer2 = buffer; buffer = richTextBox1.Text; } void richTextBox1_KeyDown(object sender, KeyEventArgs e) { if (e.Control && e.KeyCode == Keys.Z) { this.richTextBox1.Text = buffer2; } } private void button1_Click(object sender, EventArgs e) { richTextBox1.Text = "Changed"; }
Basically I write my own Undo function. All I do is store the old value in one buffer variable and the new value in the second buffer variable. Each time the text changes, these values ββare updated. Then, if the user presses "CTRL-Z", he replaces the text with the old value. Hack? Small. But it works for the most part.
Bfree
source share