Click here to Skip to main content
15,901,666 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How do you search within a RichTextBox without the help of a textbox. Here is the code that does this:

VB
Imports System.IO

Public Class Form1
    Dim start As Integer = 0

    Dim replacements As New Dictionary(Of String, List(Of String))
    Dim parts() As String

    Dim nextCheckIndex As Integer = 0
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Using reader As New StreamReader("C:\Users\Acer\Desktop\Text Files1\output18.txt")
            Do Until reader.EndOfStream
                parts = reader.ReadLine().Split("|"c)


                If replacements.ContainsKey(parts(0)) Then
                    replacements(parts(0)).Add(parts(1))

                Else
                    Dim newWordList As New List(Of String)
                    newWordList.Add(parts(1))
                    replacements.Add(parts(0), newWordList)
                End If


            Loop
        End Using

        RichTextBox1.Text = "You gave a bad advice, irregardless of your intention. You provided a bad advice, irregardless of your intention. "
    End Sub
    
    Private Sub btnFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFind.Click

        Dim startindex As Integer = 0

        If RichTextBox1.Text.Length > 0 Then

            startindex = FindMyText(textBox1.Text.Trim, start, RichTextBox1.Text.Length)

        End If


        ' If string was found in the RichTextBox, highlight it
        If startindex >= 0 Then
            ' Set the highlight color as red
            RichTextBox1.SelectionColor = Color.Red
            ' Find the end index. End Index = number of characters in textbox
            Dim endindex As Integer = textBox1.Text.Length
            ' Highlight the search string
            RichTextBox1.Select(startindex, endindex)
            ' mark the start position after the position of
            ' last search string
            start = startindex + endindex
        End If
    End Sub


    Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged

    End Sub


    Private Sub BtnClose_Click(sender As System.Object, e As System.EventArgs) Handles BtnClose.Click
        Me.Close()
    End Sub

    Private Sub BtnDelete_Click(sender As System.Object, e As System.EventArgs) Handles BtnDelete.Click
        textBox1.Clear()

    End Sub
End Class




When I check a word in a RichTextBox if it is in a dictionary with the help of a textBox, it is working. But when I use a RichTextBox without the help of a textbox, it refuses to search after I edit the code. Please help me to do away with the textBox!

Please use my dictionary file to test the program.
Posted
Updated 25-May-16 22:30pm
v13
Comments
OriginalGriff 31-Dec-15 10:57am    
What have you tried?
Where are you stuck?
What help do you need?
[no name] 31-Dec-15 10:59am    
I want to check a word in a RichTextBox if it is in a dictionary. When I use a TextBox to check if a word is in a RichTextBox it is working.
OriginalGriff 31-Dec-15 11:16am    
Sorry, but that doesn't make much sense with the code you are showing.
Where is the dictionary?
When you use a rich text box instead of a text box what happens that you didn't expect, or doesn't happen that you did?
How did you try using a rich text box?

Remember that we can't see your screen, access your HDD, or read your mind - we only get to work with exactly what you tell us!
[no name] 31-Dec-15 12:28pm    
Check the whole code now. It should be easy to understand.
OriginalGriff 31-Dec-15 12:35pm    
"what happens that you didn't expect, or doesn't happen that you did?"

I can't run your code to check - I don't have access to your HDD, remember?

1 solution

Try using the spell check API - About the Spell Checking API[^].
 
Share this answer
 
Comments
[no name] 4-Jan-16 6:53am    
Help me with this code please.

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