Visual Basic: RichTextBox Control

SelChange Event Example

This example checks the size of the current selection to see if the menu commands for cutting or copying text to the Clipboard should be enabled. To try this example, put a RichTextBox control and three Menu controls on a form to create a menu with commands to cut and copy. Paste this code into the SelChange event of the RichTextBox control. Then run the example.

  Private Sub RichTextBox1_SelChange()
   If RichTextBox1.SelLength > 0 Then
      EditCutMenu.Enabled = True
      EditCopyMenu.Enabled = True
   Else
      EditCutMenu.Enabled = False
      EditCopyMenu.Enabled = False
   End If
End Sub