C# Tutorial 26: Search and highlight text in Textbox or richTextBox in C#

C# Tutorial 26: Search and highlight text in Textbox or richTextBox in C#

How to highlight occurrences of a search term in text in Visual Studio Highlight Find Results C# Highlight all occurrences of selected word – Visual Studio C…
Video Tutorial Rating: 4 / 5

Don’t forget to check out our other video tutorials or share this video with a friend.

1 Star2 Stars3 Stars4 Stars5 Stars 0 votes
Loading... 5,389 views





20 responses to “C# Tutorial 26: Search and highlight text in Textbox or richTextBox in C#”

  1. J. Bertilsson says:

    I think It would be a smarter choice to use streamreader to open the file

  2. Robert Carlson says:

    With this code it un-formats my RTF, say I have set font to a size and
    color, as soon as I do a search BOOM no more size and color. Do you have a
    fix for this?

  3. Alex Johnson says:

    What is RichTextBoxFinds for a normal textbox? please help.

  4. Rasyid Safie says:

    can you teach us how to search and open doc. file in VS??

  5. Lasaphon says:

    How to count number of highlight?

  6. Ferii24 says:

    This video saved my life! Thank you very much! :)

  7. Ricardo Garcia says:

    Greetings;
    Once again nice tutorial.
    You forgot to prevent users from messing up teir heads (lol).
    As i was learning this i found myself with some issues.
    1) Scrolling my RichTextBox (to find the matching words – while a seach is
    active)
    the RTB is always showing the it’s first lines / the top of the file)

    I believe that to prevent this we have to know how to:
    – Go to the first matching word
    – Go to next found word (with a button for example)

    Maybe some extra coding is needed. I’m not sure yet; as “search” funtion is
    new for me.

    Can you show us how it could be done?
    Thanks in Advance

  8. k.ansudeen Imran says:

    hi!!!!!!!!! can u upload a video about how to open command prompt using
    c#?also how to run commands through c#?

  9. PCGaming300 says:

    The one problem with the highlighting is that it is case sensitive

  10. preethi vps says:

    how can you reference a xml file which is uploaded in rich textbox.if it
    is in c drive then fine it it is in rich text box.. want to know for RTB.

    var doc =
    XDocument.Load(@”C:UsersIT-AdministratorDesktop2014-01-07_Middlesex.xml”);
    working ….fine……

  11. Ricardo G. says:

    It would be good to clarify what the integer is…
    Index = ???
    I believe it’s the cursor location inside the textBox. But not sure

  12. Bruno Camargo says:

    thanks

  13. pancowong says:

    dont work in find number.

  14. craisin1 says:

    My question is, why do you initialize the RichTextBox.Text back to blank
    and then re-input the same text value? Anyway, it put me on the right track
    and I thank you for that. Although I use VB.Net, it is dead easy to
    interpret C# Code into VB.Net (and vice-versa). Don’t you all just love the
    .Net framework? 🙂

  15. craisin1 says:

    For the search to work more than once (i.e. a subsequent search is
    performed) you must alter the first “While” statement to: while (index < richTextBox1.Text.LastIndexOf(textBox1.Text, richTextBox1.TextLength)

  16. laszap says:

    i really thank you for your very useful videos. in this tutoarial, the
    program underlines the line “index = richTextBox1.Text.IndexOf(textBox1,
    index) + 1;” telling that this method doesn’t exit with these arguments.
    How can i fix it ?

  17. Paul Andrew Doctolero says:

    Ghjhbkiguhhjjioiujgigtfjhfhfsfchk

  18. Yanky Kalifornia says:

    thank for the video

  19. Chee Yi Xu says:

    how do i search the word regardless of letter case?

  20. Jeremy Munene says:

    Firstly, thanks for these tutorials. Secondly when I search the first time
    its fine, but the second time it does not search

Leave a Reply

Your email address will not be published. Required fields are marked *