hi
I am using An mdi form which contain many child form and mdi form contain ToolStrip1 in that redo & cut button are not working plz help me out of this

Private Sub toolredo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles toolredo.Click

    Dim activeChild As Form = Me.ActiveMdiChild
    If (Not activeChild Is Nothing) Then
        Try
            Dim tb As TextBox = CType(activeChild.ActiveControl, TextBox)
           If TextBox.CanRedo = True Then
                If TextBox.RedoActionName <> "Delete" Then
                   TextBox.Redo()
                End If
            End If
        Catch
            MessageBox.Show("You need to select a TextBox.")
        End Try
    End If
End Sub

Dani AI

Generated

Short answer: the WinForms TextBox does not provide a Redo API — it only exposes Undo via TextBoxBase — so calling Redo on a System.Windows.Forms.TextBox produces the error you saw. The built-in redo/redo-action-name support is implemented on RichTextBox (it exposes CanRedo / Redo). (learn.microsoft.com)

Two practical options (pick one):

  1. Use RichTextBox (recommended if you can). Put a RichTextBox on the child forms and have the MDI ToolStrip call the focused control’s Redo() when available. Example toolbar handler (VB.NET):
Private Sub toolRedo_Click(sender As Object, e As EventArgs) Handles toolRedo.Click
    Dim child = Me.ActiveMdiChild
    If child Is Nothing Then Return
    Dim focused = child.ActiveControl
    Dim rtb = TryCast(focused, RichTextBox)
    If rtb IsNot Nothing AndAlso rtb.CanRedo Then rtb.Redo()
End Sub

RichTextBox’s CanRedo/Redo are documented by Microsoft. (learn.microsoft.com)

  1. Keep TextBox but implement your own undo/redo stack (when switching controls isn’t feasible). Typical approach: maintain two stacks (undo/redo) that store the previous text and caret position; push a snapshot on user edits, clear redo on new edits, and restore snapshots on Undo/Redo. Use a boolean guard to avoid pushing history while programmatically restoring state. Also be aware the framework Undo behavior has quirks (and Undo does not behave inside KeyPress/TextChanged handlers the same way as user-level operations), so test carefully. (learn.microsoft.com)

Notes tied to earlier replies: was right to point out using the control instance (not the type name) when checking CanRedo/Redo. ’s suggestion to use RichTextBox is the simplest fix if you need built-in redo. Finally, ensure the control you grab from the active MDI child is the actual text control (nested containers can hide the focused control).

Recommended Answers

All 5 Replies

Off the top of my head it looks like you should be using tb.CanRedo instead of TextBox.CanRedo, etc. If that doesn't fix it you'll probably have to show your code for the custom properties and methods you're using.

i had made changes bu it show me error that redo is not a member of system.windows.form.textbox

That means you'll have to create your own functions to do that. Probably something along the lines of storing the changes to the textbox, through the TextChanged event.

no how we do undo and redo on our system same like that happen on my software right now undo work properly bt redo dose nt work so need the code for redo

use a RichTextBox instead. It supports Redo.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.