Home Forums WinForms controls Other WinForms controls Wintextbox undo Reply To: Wintextbox undo

User (Old forums)
Member
Post count: 23064

The TextBoxArea does not support the Undo() method. Now it is possible to implement one fairly easily, doing something like this :

C#:

private void Form1_Load(object sender, System.EventArgs e)
{
winTextBox1.TextBoxArea.GotFocus += new EventHandler( TextBoxArea_GotFocus );
winTextBox1.TextBoxArea.KeyUp += new KeyPressEventHandler( TextBoxArea_KeyUp );
}

private string m_CachedText = string.Empty;

private void TextBoxArea_KeyUp(object sender, KeyEventArgs e)
{
if( e.KeyCode == Keys.Escape )
{
winTextBox1.TextBoxArea.Text = m_CachedText;
winTextBox1.TextBoxArea.Select( 0, winTextBox1.TextBoxArea.Text.Length );
}
}

private void TextBoxArea_GotFocus(object sender, EventArgs e)
{
m_CachedText = winTextBox1.TextBoxArea.Text;
}

Imported from legacy forums. Posted by André (had 2960 views)