469,269 Members | 1,006 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,269 developers. It's quick & easy.

textbox delete and undo

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
Dec 29 '06 #1
5 5262
Steve,

I tested it in version 2003 but works perfectly for me.

Cor

"Steve" <s.*****@comcast.netschreef in bericht
news:ul**************@TK2MSFTNGP04.phx.gbl...
>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


Dec 29 '06 #2
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

"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:OH**************@TK2MSFTNGP04.phx.gbl...
Steve,

I tested it in version 2003 but works perfectly for me.

Cor

"Steve" <s.*****@comcast.netschreef in bericht
news:ul**************@TK2MSFTNGP04.phx.gbl...
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


Dec 29 '06 #3
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

"Steve" <s.*****@comcast.netwrote in message
news:%2******************@TK2MSFTNGP02.phx.gbl...
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

"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:OH**************@TK2MSFTNGP04.phx.gbl...
Steve,

I tested it in version 2003 but works perfectly for me.

Cor

"Steve" <s.*****@comcast.netschreef in bericht
news:ul**************@TK2MSFTNGP04.phx.gbl...
>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
>
>


Dec 29 '06 #4
Hi Steve,

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

HTH

Martin
"Steve" <s.*****@comcast.netwrote in message
news:ul**************@TK2MSFTNGP04.phx.gbl...
>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


Dec 30 '06 #5
I ended up discovering that through trial and error. So I guess that undo
pulls from the clipboard instead of an undo buffer?

"Martin Horn" <te**@test.comwrote in message
news:JI*******************@newsfe6-gui.ntli.net...
Hi Steve,

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

HTH

Martin
"Steve" <s.*****@comcast.netwrote in message
news:ul**************@TK2MSFTNGP04.phx.gbl...
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


Dec 31 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Susan Bricker | last post: by
6 posts views Thread by Altramagnus | last post: by
reply views Thread by Marco Liedekerken | last post: by
reply views Thread by Crouchie1998 | last post: by
2 posts views Thread by Mike Fox | last post: by
10 posts views Thread by garyusenet | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.