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..
 

ayan

Member
Joined
Jun 9, 2004
Messages
18
Programming Experience
Beginner
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
 

ayan

Member
Joined
Jun 9, 2004
Messages
18
Programming Experience
Beginner
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?
 

lOnEr

Member
Joined
Jun 18, 2004
Messages
14
Programming Experience
Beginner
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
 

.paul.

Well-known member
Joined
May 22, 2007
Messages
212
Programming Experience
1-3
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
 
Top Bottom