Click here to Skip to main content
15,924,318 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi.
i have one rich text box as txtshowfile, one text box as txtsearchgerman.when i am click on button event it should read one line and when i click second time it should read second line.

i am using this code.
C#
int textEnd = txtshowfile.TextLength;
                    int  index = 0;
                    int lastIndex  = txtshowfile.Text.LastIndexOf(txtsearchgerman.Text);
                                           while (index < lastIndex)
                        {
                            txtshowfile.Find(txtsearchgerman.Text, index, textEnd, RichTextBoxFinds.None);
                            txtshowfile.SelectionBackColor = Color.Yellow;
                            index = txtshowfile.Text.IndexOf(txtsearchgerman.Text, index) + 1;
                        }

when i search specific word than it gives all that word.but i want to read line by line word for each click.

Thanks in advance.....

[edit]"Treat my content as plain text..." option disabled - OriginalGriff[/edit]
Posted
Updated 22-Jan-12 21:07pm
v2
Comments
Sergey Alexandrovich Kryukov 23-Jan-12 3:24am    
The question is not fully defined. Do you think there is only one class named RichTextBox? No! You need to specify fully-qualifies type name, with namespace. You also need to tag the UI library. WPF, Forms, what?
--SA
mayankshrivastava 23-Jan-12 4:07am    
hi,i have a one richtextbox as txtshowfile and one text box as txtsearchgerman and one button ok
suppose there is a 10 sentences in txtshowfile line by line.i want to search a one word from txtshowfile.that word i write in txtsearchgerman ok.
when i click on button then i want specific search word as highlight.it works
but i want line by line check .
if In first line there are three specific words then i want all three word highlighted.
Hope you understand.
its urgent please help me out.

In order to do that, you need to move index out of the method, and into the class:

C#
int index = 0;
private void ReadNextLine()
   {
   ...
   }
That way, it will be preserved between button clicks, assuming this is WinForms.
 
Share this answer
 
C#
int textEnd = txtshowfile.TextLength;
    int index = 1;
    int prevIndex = Convert.ToInt16( txtshowfile.Tag);
    int lastIndex = txtshowfile.Text.LastIndexOf(txtsearchgerman.Text);
    txtshowfile.SelectionBackColor = Color.White;
    prevIndex = txtshowfile.Text.IndexOf(txtsearchgerman.Text, prevIndex + 1);
    txtshowfile.Tag = prevIndex;
    index = prevIndex;
    if (prevIndex  < 0)
  {
      index = 0;
      txtshowfile.Tag = 0;
  }
        txtshowfile.Find(txtsearchgerman.Text, index, textEnd, RichTextBoxFinds.None);
        txtshowfile.SelectionBackColor = Color.Yellow;
        index = txtshowfile.Text.IndexOf(txtsearchgerman.Text, index) + 1;

}
 
Share this answer
 
Comments
mayankshrivastava 23-Jan-12 3:56am    
Thanks for reply
its working but i want if in first line there are more then one specific word so all are highlighted.
RDBurmon 23-Jan-12 4:07am    
Elaborate your statement with example please .
mayankshrivastava 23-Jan-12 4:52am    
hi,i have a one richtextbox as txtshowfile and one text box as txtsearchgerman and one button ok suppose there is a 10 sentences in txtshowfile line by line.i want to search a one word from txtshowfile.that word i write in txtsearchgerman ok. when i click on button then i want specific search word as highlight.it works but i want line by line check . if In first line there are three specific words then i want all three word highlighted. Hope you understand. its urgent please help me out.
split it by "\n" you can get all lines in array
 
Share this answer
 
for (int i = 0; i >= richTextBox1.Lines.Count; i++)
{
// you can do what ever you want with the below one
richTextBox1.Lines[ i ];
}
 
Share this answer
 

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