Imports Infragistics.Win.UltraWinSpellChecker
'A reference to the last clicked error in the rich text box (Nothing if no error was clicked last)
Private lastClickedError As [Error] = Nothing
Private Sub contextMenuAddToDictionary_Click(ByVal sender As Object, ByVal e As EventArgs)
'Add the last clicked error to the user dictionary
Me.ultraSpellChecker1.AddWordToUserDictionary(Me.lastClickedError.CheckedWord)
End Sub
Private Sub contextMenuIgnoreAll_Click(ByVal sender As Object, ByVal e As EventArgs)
'Ignore all instances of the last clicked error
Me.ultraSpellChecker1.IgnoreAll(Me.lastClickedError.CheckedWord)
End Sub
Private Sub contextMenuSuggestion_Click(ByVal sender As Object, ByVal e As System.EventArgs)
'Get the menu item that was clicked
Dim suggestionItem As MenuItem = sender
'Select the error in the rich text box
Me.richTextBox1.Select( _
Me.lastClickedError.StartIndex, _
Me.lastClickedError.EndIndex - Me.lastClickedError.StartIndex + 1)
'Replace the selected error with the suggestion that was clicked
Me.richTextBox1.SelectedText = suggestionItem.Text
End Sub
Private Sub richTextBox1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles richTextBox1.MouseDown
'Get the error at the point where the user clicked in the rich text box
Dim point As Point = New Point(e.X, e.Y)
Me.lastClickedError = Me.ultraSpellChecker1.GetErrorAtPoint(Me.richTextBox1, point)
End Sub
Private Sub spellingContextMenu_Popup(ByVal sender As Object, ByVal e As EventArgs) Handles spellingContextMenu.Popup
'Clear the menu items previously added to the context menu
Me.spellingContextMenu.MenuItems.Clear()
'If the last clicked spot on the rich text box was over an error...
If (Not Me.lastClickedError Is Nothing) Then
'If there are no suggestions...
If (Me.lastClickedError.Suggestions.Count = 0) Then
'Add the "no spelling suggestions" menu item and disable it
Dim noSuggestionsItem As MenuItem = Me.spellingContextMenu.MenuItems.Add("(no spelling suggestions)")
noSuggestionsItem.Enabled = False
'Otherwise, if there are suggestions...
Else
'Add suggestion menu items to the context menu
Dim i As Integer
For i = 0 To Me.lastClickedError.Suggestions.Count - 1
Me.spellingContextMenu.MenuItems.Add( _
Me.lastClickedError.Suggestions(i), _
New EventHandler(AddressOf Me.contextMenuSuggestion_Click))
Next
End If
'Add a separator item to the context menu
Me.spellingContextMenu.MenuItems.Add("-")
'Add the "Add to Dictionary" menu item
Dim addItem As MenuItem = Me.spellingContextMenu.MenuItems.Add( _
"Add to Dictionary", _
New EventHandler(AddressOf Me.contextMenuAddToDictionary_Click))
'Add the "Ignore All" menu item
Me.spellingContextMenu.MenuItems.Add( _
"Ignore All", _
New EventHandler(AddressOf Me.contextMenuIgnoreAll_Click))
End If
End Sub