This is a migrated thread and some comments may be shown as answers.

Some Shortcut Keys not working in RadTextBox

1 Answer 141 Views
TextBox
This is a migrated thread and some comments may be shown as answers.
Alan
Top achievements
Rank 1
Alan asked on 31 Jan 2012, 05:30 PM
Ctrl+A (Select All)
Ctr+Y (Redo)
are not working in RadText Boxes.
Also, is there a way to change the undo being  done in RadTextBoxes to be a character at a time.

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 02 Feb 2012, 12:56 PM
Hi Alan,

Thank you for writing.

Indeed, RadTextBox currently does not support redo operation. However, undo and select all are available and the undo functionality works exactly the way the standard MIcrosoft text box does. Your suggestions for the redo operation and for the undo per character functionality are quite reasonable and this is why I will add them as feature requests in our PITS system. At the following links, you can add your vote for these requests:

Meanwhile, please refer to the following snippet, which demonstrates how to achieve the desired behavior with a stack:
public partial class Form1 : Form
{
    Stack<string> undoStack = new Stack<string>();
    Stack<string> redoStack = new Stack<string>();
 
    public Form1()
    {
        InitializeComponent();
 
        radTextBox1.TextChanged += new EventHandler(radTextBox1_TextChanged);
        radTextBox1.KeyDown += new KeyEventHandler(radTextBox1_KeyDown);
        undoStack.Push(radTextBox1.Text);
 
    }
 
    bool preventUpdate = false;
 
    void radTextBox1_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.Control && e.KeyCode == Keys.Y && redoStack.Count > 0)
        {
            radTextBox1.Text = redoStack.Pop();
        }
        if (e.Control && e.KeyCode == Keys.Z && undoStack.Count > 0)
        {
            string str = undoStack.Pop();
            int caretPosition = radTextBox1.SelectionStart;
 
            redoStack.Push(str);
            preventUpdate = true;
            radTextBox1.Text = str;
            radTextBox1.SelectionStart = caretPosition;
            preventUpdate = false;
        }
    }
 
    void radTextBox1_TextChanged(object sender, EventArgs e)
    {
        radTextBox1.ClearUndo();
        if (!preventUpdate)
        {
            RadTextBox textBox = (RadTextBox)sender;
            undoStack.Push(radTextBox1.Text);
        }
    }
}

I hope that the provided information addresses your question. Your Telerik points have been updated for this feature request.
 
Greetings,
Stefan
the Telerik team

SP1 of Q3’11 of RadControls for WinForms is available for download (see what's new).

Tags
TextBox
Asked by
Alan
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or