C# Tutorial - How to Search and Highlight Text in a RichTextBox | FoxLearn

preview_player
Показать описание
How to Search and Highlight Text in a RichTextBox in C#. The C# Basics beginner course is a free C# Tutorial Series that helps beginning programmers learn the basics of the C# Programming Language

Searching words in a text and highlighting them using c#
Search and highlight text in Textbox or richTextBox in C#
Highlight all searched word in richtextbox C#
c# - search and highlight text in textbox
How to find the text and highlight all text in RichTextBox of windows forms using c#
How do you search for a string in a rich text box and highlight all found or highlight each line in c#
RichTextBox Find the text and Highlight all text in c#
Рекомендации по теме
Комментарии
Автор

Very good, thanks!! Just one comment --- at end of while loop, the assignment of startIndex should be '=', not '+='. Took me a little while to find out why all instances of my searched word were not being found.

victormckeighan
Автор

I Watch and Downloaded all Your Videos... Very Very excellent & helpful for me > Thanks

naqeebcomputers
Автор

thank u....do u know a method, class or library to insert a dynamic sizable table to richtextbox c#?

rabihg
Автор

Thank you sooo much!! This helped my immensely!!!

Verses
Автор

hey nice work keep it up .. but in my case i have my own searching method .. now i wanted to highlight the searched words .. can you help me out .. ???

faisalyousfani
Автор

Well.. I know this is an old Video but that code has an error and it will not work as intended. at the end of the while loop, the startIndex variable increments with the last found word index value plus its length, with the intention of continuing the search from the last match. The problem is that incrementing the value will skip many hits. The value should be incremented but changed: It should be "startIndex = wordStartIndex + word.Length;"
cheers

nebis
Автор

hello...thanku its amazing....kindly help me that who we (count) these highlighted words

muhammadshaoorsiddique
Автор

nice
i have surce code have some error
cam i connact for u to help me ?

ameerabdaljabar
Автор

Hi! I was wondering: How would I accomplish this from a different form? Say, if I were to press Ctrl+F, then Form2 should come up, with the find, find next, etc.


I have the code (It works!) except that if I enter the richtextbox after find a word, the text is all blue. Here is my source:


public static void Find(RichTextBox rtb, String word, Color color)
{
rtb.SelectionStart = 0;
rtb.SelectionLength = rtb.TextLength;
rtb.SelectionColor = Color.Black;
if (word == "")
{
return;
}
int s_start = rtb.SelectionStart, startIndex = 0, index;
while ((index = rtb.Text.IndexOf(word, startIndex)) != -1)
{
rtb.Select(index, word.Length);
rtb.SelectionColor = color;
startIndex = index + word.Length;
}
}

private void button1_Click(object sender, EventArgs e)
{
Find(richtext, textBox1.Text, Color.Blue);
}




That is in Form2.cs I already know how to connect Form1 to Form2, I just need help fixing the selectioncolor after they find some text.

heartbreaker-tv
Автор

yess.. my problem solved,  after watch this video

muhammadfahriansyah
Автор

Sorry but 3:14 I can't find the Find method is word!!

alshentec
Автор

the program is wrong. startindex += must be startindex =

klausdorr
Автор

Isn't there an easier way to do this, without any indexof and shit, cause it is pretty complicated for only the back color

black_sck
Автор

nice
i have surce code have some error
cam i connact for u to help me ?

ameerabdaljabar