|
-
Oct 18th, 2007, 02:24 PM
#1
Thread Starter
New Member
Text Box undo
How do I get undo to work with a textbox. The undo in the right click menu doesn't work.
I'm new to VB so could you explain it to me as well without trying to loose me.
Thanks in advance.
EDIT: Sorry load of rubbish could a mod delete this please.
Last edited by wickedgenius; Oct 18th, 2007 at 02:25 PM.
Reason: Fixed problem
-
Oct 18th, 2007, 02:42 PM
#2
Lively Member
Re: Text Box undo
 Originally Posted by wickedgenius
How do I get undo to work with a textbox. The undo in the right click menu doesn't work.
I'm new to VB so could you explain it to me as well without trying to loose me.
Thanks in advance.
EDIT: Sorry load of rubbish could a mod delete this please.
sounds like you may have added the standard buttons on a context menu. what you need to do is while in designing the form, click on the context menu below the form and it should appear. double-click on the Undo and you should go to code view. You will notice it is empty or some sort of comment in there. Now, do soemthing like this:
vb Code:
Public Class Form1
#Region " declarations "
Dim strUndoData As String = ""
Dim strRedoData As String = ""
#End Region
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
If Not strUndoData <> "" Then
strUndoData = TextBox1.Text
End If
End Sub
Private Sub ctxMenu_UndoMePlease_OhYesPlease_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ctxMenu_UndoMePlease_OhYesPlease.Click
strRedoData = TextBox1.Text
TextBox1.Text = strUndoData
strUndoData = ""
ctxMenu_UndoMePlease_OhYesPlease.Enabled = False
ctxMenu_RedoMePlease_OhGodNotAgain.Enabled = True
End Sub
Private Sub ctxMenu_RedoMePlease_OhGodNotAgain_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ctxMenu_RedoMePlease_OhGodNotAgain.Click
TextBox1.Text = strRedoData
strUndoData = strRedoData
strRedoData = ""
ctxMenu_RedoMePlease_OhGodNotAgain.Enabled = False
ctxMenu_UndoMePlease_OhYesPlease.Enabled = True
End Sub
End Class
Last edited by RickyH; Oct 18th, 2007 at 02:55 PM.
-
Oct 18th, 2007, 02:44 PM
#3
Lively Member
Re: Text Box undo
 Originally Posted by wickedgenius
I'm new to VB so could you explain it to me as well without trying to loose me.
Basically, you need someplace to store the undo data. The above is just a simple setup where you can only undo one level. You can get more complicated and provide multiple levels of undo, but this should suffice for a simple example.
As you can see, you need to store the data you are changing back to, much like having another textbox on the screen that when you change something, it will be stored there until time comes that whenyou decide to change back, you grab the data from the hidden textbox and put it in the visible text box. in this case, instead of using a hidden textbox, we are using a hidden string variable named strUndoData & strRedoData.
-
Oct 18th, 2007, 03:26 PM
#4
Junior Member
Re: Text Box undo
Dosen't a textbox have a Undo Property, I could be wrong though...
-
Oct 18th, 2007, 08:59 PM
#5
Junior Member
Re: Text Box undo
As long as there is text in the textbox I am able to right click and select undo. If done multiple times, it will flip-flop between values. There is a note in help stating "The Undo method does not work with the KeyPress or TextChanged events." You may want to go here and read about the process: http://msdn2.microsoft.com/en-us/lib...base.undo.aspx
Jim
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|