textbox delete and undo

S

Steve

I have created my own context menu. Everything works except undo'ing
deleted text. My code for these two events are:

Private Sub tsmiUndo_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles tsmiUndo.Click

' Undo the last thing the user did and clear the undo buffer to make
sure that clicking
' Undo again doesn't redo the last thing undone.

Dim tb As TextBox = CType(Me.ActiveControl, TextBox)
If tb.CanUndo = True Then
tb.Undo()
tb.ClearUndo()
End If

Does anyone have an idea of why this doesn't work?

Thanks

Steve

End Sub

Private Sub tsmiDelete_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles tsmiDelete.Click

' Delete the selected text (if any) by initalizing the textbox.


If (TypeOf Me.ActiveControl Is TextBox) Then
Dim tb As TextBox = CType(Me.ActiveControl, TextBox)
If tb.SelectionLength > 0 Then
tb.SelectedText = ""
End If
End If

End Sub
 
S

Steve

Thanks for testing...

Are you remembering that you have to set the contextmenuscript in the
textbox properties to your contextmenuscript instead of the default?

Steve
 
S

Steve

One more note. If I don't set the textbox's contextmenuscript property
equal to the contextmenuscript you added, then the textbox works using the
default (set to none). But if you set it to the contextmenuscript field you
added, it doesn't appear to work. I tried it in a new 2005 project with two
textboxes and the contextmenuscript (with two items - delete and undo) -
same result.

Steve
 
M

Martin Horn

Hi Steve,

use tb.cut() instead of tb.SelectedText = "" and you should find that undo
will work then.

HTH

Martin
 
S

Steve

I ended up discovering that through trial and error. So I guess that undo
pulls from the clipboard instead of an undo buffer?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top