I’m working on a very simple Undo feature for a TextBox and I’ve got a weird problem. When I try to take strings from the Stackthat holds all the changes and put them inside the Textbox I don’t see any changes.
I made a little Debug Label to check if this is really working or not.
I found out that it is working in the label, but in the Textbox it uses its own Undo functions.
Is there a way to cancel or override the Textbox Undo and use my own function?
Here is sample code from the change I made:
private void Form1_KeyDown(object sender, KeyEventArgs e)
if (e.KeyCode == Keys.Z && (ModifierKeys & Keys.Control) == Keys.Control)
{
nameTextBox.Text = undoName.GetLastChange(); //--> not working
undoDebuglabel.Text = undoName.GetLastChange(); --> working
}
}
The GetLastChange() is getting the info from a Stack inside the class.
It’s like the Textbox is not letting me to see the changes.
Could it be because I’m using the same shortcut, CTRL + Z to do it?
Clear the Textbox’s own stack by using the ClearUndo method. Try this: