textbox delete and undo

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve

    #1

    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.EventArg s) 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.Active Control, 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_Clic k(ByVal sender As Object, ByVal e As
    System.EventArg s) Handles tsmiDelete.Clic k

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


    If (TypeOf Me.ActiveContro l Is TextBox) Then
    Dim tb As TextBox = CType(Me.Active Control, TextBox)
    If tb.SelectionLen gth 0 Then
    tb.SelectedText = ""
    End If
    End If

    End Sub


  • Cor Ligthert [MVP]

    #2
    Re: textbox delete and undo

    Steve,

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

    Cor

    "Steve" <s.arndt@comcas t.netschreef in bericht
    news:uloaRoxKHH A.3268@TK2MSFTN GP04.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.EventArg s) 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.Active Control, 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_Clic k(ByVal sender As Object, ByVal e As
    System.EventArg s) Handles tsmiDelete.Clic k
    >
    ' Delete the selected text (if any) by initalizing the textbox.
    >
    >
    If (TypeOf Me.ActiveContro l Is TextBox) Then
    Dim tb As TextBox = CType(Me.Active Control, TextBox)
    If tb.SelectionLen gth 0 Then
    tb.SelectedText = ""
    End If
    End If
    >
    End Sub
    >
    >

    Comment

    • Steve

      #3
      Re: textbox delete and undo

      Thanks for testing...

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

      Steve

      "Cor Ligthert [MVP]" <notmyfirstname @planet.nlwrote in message
      news:OH5gQdyKHH A.3268@TK2MSFTN GP04.phx.gbl...
      Steve,
      >
      I tested it in version 2003 but works perfectly for me.
      >
      Cor
      >
      "Steve" <s.arndt@comcas t.netschreef in bericht
      news:uloaRoxKHH A.3268@TK2MSFTN GP04.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.EventArg s) 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.Active Control, 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_Clic k(ByVal sender As Object, ByVal e As
      System.EventArg s) Handles tsmiDelete.Clic k

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


      If (TypeOf Me.ActiveContro l Is TextBox) Then
      Dim tb As TextBox = CType(Me.Active Control, TextBox)
      If tb.SelectionLen gth 0 Then
      tb.SelectedText = ""
      End If
      End If

      End Sub
      >
      >

      Comment

      • Steve

        #4
        Re: textbox delete and undo

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

        Steve

        "Steve" <s.arndt@comcas t.netwrote in message
        news:%23Lky%23n 2KHHA.1248@TK2M SFTNGP02.phx.gb l...
        Thanks for testing...
        >
        Are you remembering that you have to set the contextmenuscri pt in the
        textbox properties to your contextmenuscri pt instead of the default?
        >
        Steve
        >
        "Cor Ligthert [MVP]" <notmyfirstname @planet.nlwrote in message
        news:OH5gQdyKHH A.3268@TK2MSFTN GP04.phx.gbl...
        Steve,

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

        Cor

        "Steve" <s.arndt@comcas t.netschreef in bericht
        news:uloaRoxKHH A.3268@TK2MSFTN GP04.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.EventArg s) 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.Active Control, 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_Clic k(ByVal sender As Object, ByVal e As
        System.EventArg s) Handles tsmiDelete.Clic k
        >
        ' Delete the selected text (if any) by initalizing the textbox.
        >
        >
        If (TypeOf Me.ActiveContro l Is TextBox) Then
        Dim tb As TextBox = CType(Me.Active Control, TextBox)
        If tb.SelectionLen gth 0 Then
        tb.SelectedText = ""
        End If
        End If
        >
        End Sub
        >
        >
        >
        >

        Comment

        • Martin Horn

          #5
          Re: textbox delete and undo

          Hi Steve,

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

          HTH

          Martin


          "Steve" <s.arndt@comcas t.netwrote in message
          news:uloaRoxKHH A.3268@TK2MSFTN GP04.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.EventArg s) 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.Active Control, 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_Clic k(ByVal sender As Object, ByVal e As
          System.EventArg s) Handles tsmiDelete.Clic k
          >
          ' Delete the selected text (if any) by initalizing the textbox.
          >
          >
          If (TypeOf Me.ActiveContro l Is TextBox) Then
          Dim tb As TextBox = CType(Me.Active Control, TextBox)
          If tb.SelectionLen gth 0 Then
          tb.SelectedText = ""
          End If
          End If
          >
          End Sub
          >
          >

          Comment

          • Steve

            #6
            Re: textbox delete and undo

            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" <test@test.comw rote in message
            news:JItlh.2634 7$Qa6.12386@new sfe6-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.arndt@comcas t.netwrote in message
            news:uloaRoxKHH A.3268@TK2MSFTN GP04.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.EventArg s) 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.Active Control, 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_Clic k(ByVal sender As Object, ByVal e As
            System.EventArg s) Handles tsmiDelete.Clic k

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


            If (TypeOf Me.ActiveContro l Is TextBox) Then
            Dim tb As TextBox = CType(Me.Active Control, TextBox)
            If tb.SelectionLen gth 0 Then
            tb.SelectedText = ""
            End If
            End If

            End Sub
            >
            >

            Comment

            Working...