AutoVerbMenu property was not upgraded

In Visual Basic 6.0, the AutoVerbMenu property of a RichTextBox control is used to display a context menu (or shortcut menu) with a set of standard commands.

In Visual Basic 2008, the AutoVerbMenu property no longer exists. To provide a context menu for a RichTextBox control, use a ContextMenuStrip component. To create a context menu that duplicates the appearance and behavior of the AutoVerbMenu, perform the following procedure.

What to do next

  1. In Solution Explorer, right-click the form that contains the RichTextBox control and select View Designer.

  2. In the Toolbox, double-click the ContextMenuStrip component. It will be added to the Component Tray at the bottom of the designer.

  3. In the Properties window, select the (Name) property and change it to AutoVerbMenu.

  4. Select the ShowImageMargin property and set it to False.

  5. Select the Items property and then click the ellipsis button to open the Items Collection Editor.

  6. Click the Add button to add a ToolStripMenuItem.

  7. In the Property grid, select the (Name) property and change it to Undo.

  8. Select the Text property and change it to Undo.

  9. Select the ShortcutKeys property, click the drop-down button, select the Ctrl check box and select Z from the Key list.

  10. In the Select item and add to list below drop-down list, select Separator, and then click the Add button.

  11. In the Select item and add to list below drop-down list, select MenuItem, and then click the Add button four times.

  12. For each of the new menu items, set the properties as follows:

    1. For the first item, set the (Name) and Text properties to Cut and the ShortcutKeys property to Ctrl + X.

    2. For the second item, set the (Name) and Text properties to Copy and the ShortcutKeys property to Ctrl + C.

    3. For the third item, set the (Name) and Text properties to Paste and the ShortcutKeys property to Ctrl + V.

    4. For the fourth item, set the (Name) and Text properties to Delete and the ShortcutKeys property to Del.

    Click OK to close the Items Collection Editor.

  13. In the Properties window, click the Events button, and then double-click the Opened event to open the Code Editor. In the AutoVerbMenu_Opened event procedure, enter the following code.

    ' Determine if Undo should be enabled.
    If RichTextBox1.CanUndo = True Then
        Undo.Enabled = True
    Else
        Undo.Enabled = False
    End If
    ' Determine if Cut, Copy, and Paste should be enabled.
    If RichTextBox1.SelectedText <> "" Then
        Cut.Enabled = True
        Copy.Enabled = True
        Delete.Enabled = True
    Else
        Cut.Enabled = False
        Copy.Enabled = False
        Delete.Enabled = False
    End If
    ' Determine if Paste should be enabled
    If My.Computer.Clipboard.ContainsText = True Then
        Paste.Enabled = True
    Else
        Paste.Enabled = False
    End If
    
  14. In the Class Name drop-down list, select Undo. In the Method Name drop-down list, select Click. In the Undo_Click event handler add the following code.

    ' Undo the last edit operation in the RichTextBox
    If RichTextBox1.CanUndo Then
        RichTextBox1.Undo()
    End If
    
  15. In the Class Name drop-down list, select Cut. From the Method Name drop-down list, select Click. In the Cut_Click event handler add the following code.

    ' Cut the selected text and place it on the clipboard.
    If RichTextBox1.SelectedText <> "" Then
        RichTextBox1.Cut()
    End If
    
  16. In the Class Name drop-down list, select Copy. In the Method Name drop-down list, select Click. In the Copy_Click event handler add the following code:

    ' Copy the selected text and place it on the clipboard.
            If RichTextBox1.SelectedText <> "" Then
                RichTextBox1.Copy()
            End If
    
  17. In the Class Name drop-down list, select Paste. In the Method Name drop-down list, select Click. In the Paste_Click event handler add the following code.

    ' Paste the contents of the clipboard at the cursor location.
    If My.Computer.Clipboard.ContainsText Then
        RichTextBox1.Paste()
    End If
    
  18. In the Class Name drop-down list, select Delete. From the Method Name drop-down list, select Click. In the Delete_Click event handler add the following code.

    ' Delete the selected text.
    If RichTextBox1.SelectedText <> "" Then
        RichTextBox1.SelectedText = ""
    End If
    
  19. Switch back to Design view and select the RichTextBox control.

  20. In the Properties window, click the Properties button. Select the ContextMenuStrip property, and then select AutoVerbMenu from the drop-down list.

See Also

Reference

RichTextBox Control Overview (Windows Forms)

ContextMenuStrip Control Overview