simple textbox question.

lOnEr

Member
Joined
Jun 18, 2004
Messages
14
Programming Experience
Beginner
halu..im very new in this thing..
i have a form w/ corresponding textbox and a button...
i'll make a keydown event in the form..
and user input a value in the textbox and pressing "enter" a string will hold the value..
what i want is..when the user press the "esc" while editing in the textbox the previous value will appear in the textbox...

kinda mapping the undo.

tanx in advance and more power..
 
something like this?
VB.NET:
    Dim s As New Stack()
 
    Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
 	  If e.KeyCode = Keys.Escape Then
 		 Try
 			TextBox1.Text = s.Pop()
 		 Catch ex As Exception
 			MessageBox.Show(ex.Message)
 		 End Try
 	  End If
 	  If e.KeyCode = Keys.Enter Then
 		 s.Push(TextBox1.Text)
 	  End If
    End Sub
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 	  s.Push(TextBox1.Text)
    End Sub
 
you mean on textchanged event? every changes in textbox is pushed to the stack. try putting the s.push(blah) to textbox_textchanged event. is that what you mean?
 
ayan said:
you mean on textchanged event? every changes in textbox is pushed to the stack. try putting the s.push(blah) to textbox_textchanged event. is that what you mean?
ok i will try it sooner..

thanks...more power
 
to undo text in a text box, declate a form level variable - txtPrev
set it to initial text. then reset it to each new change in the textbox1 change event.
if esc is pressed you can set textbox1.text = txtPrev
 
Back
Top