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
In Solution Explorer, right-click the form that contains the RichTextBox control and select View Designer.
In the Toolbox, double-click the ContextMenuStrip component. It will be added to the Component Tray at the bottom of the designer.
In the Properties window, select the (Name) property and change it to AutoVerbMenu.
Select the ShowImageMargin property and set it to False.
Select the Items property and then click the ellipsis button to open the Items Collection Editor.
Click the Add button to add a ToolStripMenuItem.
In the Property grid, select the (Name) property and change it to Undo.
Select the Text property and change it to Undo.
Select the ShortcutKeys property, click the drop-down button, select the Ctrl check box and select Z from the Key list.
In the Select item and add to list below drop-down list, select Separator, and then click the Add button.
In the Select item and add to list below drop-down list, select MenuItem, and then click the Add button four times.
For each of the new menu items, set the properties as follows:
For the first item, set the (Name) and Text properties to Cut and the ShortcutKeys property to Ctrl + X.
For the second item, set the (Name) and Text properties to Copy and the ShortcutKeys property to Ctrl + C.
For the third item, set the (Name) and Text properties to Paste and the ShortcutKeys property to Ctrl + V.
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.
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
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
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
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
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
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
Switch back to Design view and select the RichTextBox control.
In the Properties window, click the Properties button. Select the ContextMenuStrip property, and then select AutoVerbMenu from the drop-down list.