Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is a very basic idea, and I'm sure that many improvements could be made.</p> <p>I would create a <code>String Array</code> and incrementally store the value of the <code>RichTextBox</code> (In the <code>TextChanged</code> event, under your own conditions) in the array. As you store the value, increment the value of a counter, say <code>stackcount</code>. When the user undoes, decrement the <code>stackcount</code> and set the <code>RichTextBox.Text = array(stackcount)</code>. If they redo, then increment the value of the counter and set the value again. If they undo and then change the text, then clear all values onwards.</p> <p>I am sure that many other people may have better suggestions/changes for this, so please post in comments and I will update, or edit it yourself!</p> <p><strong>Example in C#</strong></p> <pre><code>using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace RedoUndoApp { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public string[] RTBRedoUndo; public int StackCount = 0; public int OldLength = 0; public int ChangeToSave = 5; public bool IsRedoUndo = false; private void Form1_Load(object sender, EventArgs e) { RTBRedoUndo = new string[10000]; RTBRedoUndo[0] = ""; } private void undo_Click(object sender, EventArgs e) { IsRedoUndo = true; if (StackCount &gt; 0 &amp;&amp; RTBRedoUndo[StackCount - 1] != null) { StackCount = StackCount - 1; richTextBox1.Text = RTBRedoUndo[StackCount]; } } private void redo_Click(object sender, EventArgs e) { IsRedoUndo = true; if (StackCount &gt; 0 &amp;&amp; RTBRedoUndo[StackCount + 1] != null) { StackCount = StackCount + 1; richTextBox1.Text = RTBRedoUndo[StackCount]; } } private void richTextBox1_TextChanged(object sender, EventArgs e) { if (IsRedoUndo == false &amp;&amp; richTextBox1.Text.Substring(richTextBox1.Text.Length - 1, 1) == " ")//(Math.Abs(richTextBox1.Text.Length - OldLength) &gt;= ChangeToSave &amp;&amp; IsRedoUndo == false) { StackCount = StackCount + 1; RTBRedoUndo[StackCount] = richTextBox1.Text; OldLength = richTextBox1.Text.Length; } } private void undo_MouseUp(object sender, MouseEventArgs e) { IsRedoUndo = false; } private void redo_MouseUp(object sender, MouseEventArgs e) { IsRedoUndo = false; } } } </code></pre>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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