Home All Groups Group Topic Archive Search About

textbox delete and undo

Author
29 Dec 2006 7:23 AM
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

Author
29 Dec 2006 8:59 AM
Cor Ligthert [MVP]
Steve,

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

Cor

Show quoteHide quote
"Steve" <s.ar***@comcast.net> schreef in bericht
news:uloaRoxKHHA.3268@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
>
>
Author
29 Dec 2006 4:56 PM
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

Show quoteHide quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:OH5gQdyKHHA.3268@TK2MSFTNGP04.phx.gbl...
> Steve,
>
> I tested it in version 2003 but works perfectly for me.
>
> Cor
>
> "Steve" <s.ar***@comcast.net> schreef in bericht
> news:uloaRoxKHHA.3268@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
> >
> >
>
>
Author
29 Dec 2006 5:20 PM
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

Show quoteHide quote
"Steve" <s.ar***@comcast.net> wrote in message
news:%23Lky%23n2KHHA.1248@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]" <notmyfirstn***@planet.nl> wrote in message
> news:OH5gQdyKHHA.3268@TK2MSFTNGP04.phx.gbl...
> > Steve,
> >
> > I tested it in version 2003 but works perfectly for me.
> >
> > Cor
> >
> > "Steve" <s.ar***@comcast.net> schreef in bericht
> > news:uloaRoxKHHA.3268@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
> > >
> > >
> >
> >
>
>
Author
30 Dec 2006 1:20 PM
Martin Horn
Hi Steve,

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

HTH

Martin


Show quoteHide quote
"Steve" <s.ar***@comcast.net> wrote in message
news:uloaRoxKHHA.3268@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
>
>
Author
31 Dec 2006 6:13 AM
Steve
I ended up discovering that through trial and error.  So I guess that undo
pulls from the clipboard instead of an undo buffer?

Show quoteHide quote
"Martin Horn" <t***@test.com> wrote in message
news:JItlh.26347$Qa6.12386@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.ar***@comcast.net> wrote in message
> news:uloaRoxKHHA.3268@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
> >
> >
>
>