Results 1 to 2 of 2

Thread: [RESOLVED] Multiple Undo Redo for Richtextbox

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2006
    Location
    Malaysia
    Posts
    53

    Resolved [RESOLVED] Multiple Undo Redo for Richtextbox

    How to create multiple undo redo function for RTB??
    Just post what you know.

    Thanks!

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Multiple Undo Redo for Richtextbox

    Hi

    Here is something for a text box... see if this can help you...

    it was originally coded by some James Williams

    This is code for undo-ing the last action in a normal text box, with multiple undoes. There is also a redo function, but this doesnt work very well.

    VB Code:
    1. 'this undo thing works very well with normal text boxes. even records things like delete, return or paste
    2. 'the redo thing doesnt work very well, but the undo is perfect
    3.  
    4. Dim redopressed As Boolean
    5. Dim undopressed As Boolean
    6. 'change the bracketed number lower to use less system resources. the current is fine, but add another 0 and it can be slow. on slow pc's, make it lower.
    7. 'the no. in brackets is effectively the amount of changes remembered. the first change is no 1, so once youve got past the set number, undo will not work at all.
    8. 'e.g try setting it to 5
    9. Dim str(1000000) As String
    10. Dim bytChange As Double     'this was byte, but it only stored up to 255 changes, so i made it much bigger with double!
    11.  
    12. Private Sub cmdRedo_Click()
    13. If redopressed = False Then
    14.    redopressed = True
    15.    If bytChange >= 0 Then _
    16.    Text1.Text = str((bytChange + 1))
    17.    If bytChange >= 0 Then bytChange = bytChange + 1
    18. cmdRedo_Click
    19. End If
    20.  
    21. If redopressed = True Then
    22.    redopressed = False
    23.    If bytChange >= 0 Then _
    24.    Text1.Text = str((bytChange + 1))
    25.    If bytChange >= 0 Then bytChange = bytChange + 1
    26. End If
    27.  
    28. End Sub
    29.  
    30. Private Sub cmdUndo_Click()
    31.  
    32. If bytChange = 0 Then cmdUndo.Enabled = False
    33.  
    34. If undopressed = False Then
    35.    undopressed = True
    36.    If bytChange > 0 Then _
    37.    Text1.Text = str((bytChange - 1))
    38.    If bytChange >= 1 Then bytChange = bytChange - 1
    39. cmdUndo_Click   'dont ask why this has to be done twice. i have no idea, but, hey, it works :)
    40. End If
    41.  
    42. If undopressed = True Then
    43.    undopressed = False
    44.    If bytChange > 0 Then _
    45.    Text1.Text = str((bytChange - 1))
    46.    If bytChange >= 1 Then bytChange = bytChange - 1
    47. cmdRedo.Enabled = True
    48. End If
    49.  
    50. End Sub
    51.  
    52. Private Sub Form_Load()
    53. bytChange = 1
    54. undopressed = False
    55. redopressed = False
    56. End Sub
    57.  
    58. Private Sub Text1_Change()
    59. cmdUndo.Enabled = True
    60. If bytChange > 0 Then
    61. str((bytChange + 1)) = Text1.Text
    62. bytChange = bytChange + 1
    63. End If
    64.  
    65. 'Select Case bytChange        | 'This is what the whole code
    66. 'Case 0:                      | 'does really. it remembers
    67. 'str(1) = Text1.Text          | 'what the text was like each
    68. 'bytChange = 1                | 'time, and when undo is pressed,
    69. 'Case 1:                  <---| 'it works out when it is being
    70. 'str(2) = Text1.Text          | 'pressed (bytchange), and
    71. 'bytChange = 2                | 'brings back what it was then.
    72. 'Case 2:
    73. 'str(3) = Text1.Text
    74. 'bytChange = 3
    75. 'End Select
    76.  
    77. End Sub

    Hope this helps...
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width