Search from Richtextbox function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kurpeli1
    New Member
    • Oct 2019
    • 1

    Search from Richtextbox function

    I have a search textbox called "textBox3"
    and richtextbox called "lRichTextB ox1"

    I want to make a search function that when I write something to "textbox3" it will then search the text from "lRichTextBox1" .

    what i have tried





    Code:
           private void button4_Click_2(object sender, EventArgs e)
            {
                int aindex = 0;
                while (aindex <lRichTextBox1.Text.LastIndexOf(textBox3.Text))
                {
                    lRichTextBox1.Find(textBox3.Text, aindex, lRichTextBox1.TextLength, RichTextBoxFinds.None);
                    lRichTextBox1.SelectionBackColor = Color.Blue;
    
                                    aindex = lRichTextBox1.Text.IndexOf(textBox3.Text, aindex) + 1;
                
                }
            }
    But after it has found the text, it will then auto-scroll to that text. how is that done?
    Last edited by gits; Oct 21 '19, 12:30 PM. Reason: added code tags
  • SioSio
    Contributor
    • Dec 2019
    • 272

    #2
    Write lRichTextBox1.F ocus(); in button4_Click_2 , add the following description, and scroll to the cursor position.
    lRichTextBox1.S crollToCaret();
    Or
    lRichTextBox1.S elect();

    Comment

    Working...