Click here to Skip to main content
14,978,617 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In VB2010, I have a RichTextBox populated with both text and graphics. I have created a spell check routine for the RichTextBox. After correcting the first misspelling, I use scrolltocaret to display the next misspelling. However, when it scrolls all text become invisible although it looks like the scroll goes to the correct position. The graphics are still displayed in the correct position but the text is not shown.

Now if I remove all the graphics and perform the spell check again, scrolling to the next misspelling is correct and the text is visible.

Appears graphics in the RichTextBox creates a situation when the text disappears when scrolled.

Any ideas?

Many thanks.

What I have tried:

Tried removing the graphics and the text remains displayed on scrolling.
Posted
Updated 8-Mar-21 6:47am
v2
Comments
Gerry Schmitz 8-Mar-21 14:02pm
   
Probably some sort of "refresh" is needed; but since you didn't show any code...
Gary_Corbell 8-Mar-21 14:42pm
   
Thanks for you reply, Gerry......yes that is what I tried. I inserted Refresh is several places in the code and still no luck. Here is the code:

If RTB1.Text.Length > 0 Then

Dim SpellCheckWords As String() = Nothing
///Invoke Microsoft Word Spell Checker routine
Dim objWord As Object = CreateObject("Word.Application")
Dim objDoc As Object = objWord.documents.add
'Hide the Word Application
objWord.Visible = False

///Show Spell Checker Window and load Spell Checker RichTextBox with RTF data from Helper
Check.Visible = True
Check.RTB1Check.Rtf = RTB1.Rtf

///Split the Rich Text into single words
sSpellCheckWords = Check.RTB1Check.Text.Split(CChar(" "))

///Check spelling of each word
Dim oldstart As Integer = -1
Dim OldLength As Integer = -1
For Each sWord As String In sSpellCheckWords
If objWord.CheckSpelling(sWord) = False Then
dEventFlag = True
///Find location and length of first misspelled word
Check.RTB1Check.SelectionStart = Check.RTB1Check.Find(sWord)
Check.RTB1Check.SelectionLength = sWord.Length

//Scroll to the next misspelled word.
Check.RTB1Check.ScrollToCaret()

///Set color of misspelled word to red
Check.RTB1Check.SelectionColor = Color.Red

///Keep track of selection start and selection length
oldstart = Check.RTB1Check.SelectionStart
OldLength = sWord.Length

/Get and add possible suggestions to the listbox for user viewing and use.
Dim oWordSuggestions As Microsoft.Office.Interop.Word.SpellingSuggestions
oWordSuggestions = objWord.GetSpellingSuggestions(sWord)
Dim n As Integer = 1
Do While n <= oWordSuggestions.Count
Check.ListBox1.Items.Add(oWordSuggestions.Item(n).Name)
n = n + 1
Loop

///Wait for user to select the correct spelling. The listbox1 indexchanged event sets the dEventFlag to false to continue
Do While dEventFlag = True
/// process messages from UI
Application.DoEvents()
Loop

///Replace the misspelled word with user selected word
Check.RTB1Check.SelectionStart = oldstart
Check.RTB1Check.SelectionLength = OldLength
Check.RTB1Check.SelectionColor = Color.Black
If Check.ListBox1.SelectedItem IsNot Nothing Then
Dim GetNewSpelling = Check.ListBox1.SelectedItem.ToString
Check.RTB1Check.SelectedText = ""
Check.RTB1Check.SelectedText = GetNewSpelling
End If
///clear the listbox and prepare to find and display next misspelling.
Check.ListBox1.Items.Clear()
End If
///After misspelled word is correct, reset the text color to black
Check.RTB1Check.SelectionColor = Color.Black
Next sWord
objDoc.close()
objWord.quit()
MessageBox.Show("Spell Check Complete")
///Transfer correct RTF to Main RichTextBox
RTB1.Rtf = Check.RTB1Check.Rtf
Check.Close()
End If
Me.Cursor = Cursors.Default

RTB1.Focus()
Me.Cursor = Cursors.Default
Me.BringToFront()
Jo_vb.net 8-Mar-21 16:04pm
   
you could try .find method
Gary_Corbell 8-Mar-21 17:49pm
   
Ok I will give that a try and let you know......thanks for replying.
Gary_Corbell 8-Mar-21 18:37pm
   
I tried your suggestion but no go. However, I then found my problem. The rich text box had a bitmap of a red line (used for separation of topics)at the very bottom of the richtextbox and on the next line after the text ended. When I removed that or when I put two new blank lines between the last text and the line, the text did not disappear. At least now I know. Thanks for your input.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900