Note that there are some explanatory texts on larger screens.

plurals
  1. POWhen I redo using this undo/redo code, the first thing undone cannot be redone
    primarykey
    data
    text
    <p>I am using the following code in order to implement undo/redo into my application:</p> <pre><code> public struct UndoSection { public string Undo; public int Index; } </code></pre> <p>--</p> <pre><code> public UndoSection(int index, string undo) { Index = index; Undo = undo; } </code></pre> <p>--</p> <pre><code> Stack&lt;UndoSection&gt; UndoStack = new Stack&lt;UndoSection&gt;(); private void Form1_KeyDown(object sender, KeyEventArgs e) { if (e.Modifiers == Keys.None &amp;&amp; e.KeyCode == Keys.Delete) UndoStack.Push(new UndoSection(richTextBoxPrintCtrl1.SelectionStart, richTextBoxPrintCtrl1.SelectedText)); else if (e.Control &amp;&amp; e.KeyCode == Keys.Z) { e.Handled = true; undo_Click(richTextBoxPrintCtrl1, new EventArgs()); } } public string[] RTBRedoUndo; public int StackCount = 0; public int OldLength = 0; public int ChangeToSave = 5; public bool IsRedoUndo = false; </code></pre> <p>--</p> <pre><code> public void RTBTextChanged() { if (richTextBoxPrintCtrl1.TextLength - OldLength &gt;= ChangeToSave | richTextBoxPrintCtrl1.TextLength - OldLength &lt;= ChangeToSave) { StackCount += 1; RTBRedoUndo[StackCount] = richTextBoxPrintCtrl1.Text; } } public void UndoCode() { IsRedoUndo = true; if (StackCount &gt; 0 &amp;&amp; RTBRedoUndo[StackCount - 1] != null) { StackCount = StackCount - 1; richTextBoxPrintCtrl1.Text = RTBRedoUndo[StackCount]; } } public void RedoCode() { if (IsRedoUndo == false &amp;&amp; richTextBoxPrintCtrl1.Text.Substring(richTextBoxPrintCtrl1.Text.Length - 1, 1) == " ") IsRedoUndo = true; if (StackCount &gt; 0 &amp;&amp; RTBRedoUndo[StackCount + 1] != null) { StackCount = StackCount + 1; richTextBoxPrintCtrl1.Text = RTBRedoUndo[StackCount]; } </code></pre> <p>However, if I type some text in my rich text box such as: "Hello. This is my application.", It will only let me redo up to "my". It won't let me redo "application.". And if I undo all text, I then cannot redo and restore the text.</p> <p>What is causing this to behave in this manner? I really need to get this undo/redo code working correct. Could somebody help point me in the right direction, please?</p> <p>--EDIT--</p> <p>Redo code:</p> <pre><code>public void RedoCode() { if (IsRedoUndo == false &amp;&amp; richTextBoxPrintCtrl1.Text.Substring(richTextBoxPrintCtrl1.Text.Length - 1, 1) == " ") IsRedoUndo = true; if (StackCount &gt; 0 &amp;&amp; RTBRedoUndo[StackCount + 1] != null) { StackCount = StackCount + 1; richTextBoxPrintCtrl1.Text = RTBRedoUndo[StackCount]; } } </code></pre> <p>It is called by a button click, using RedoCode();</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload