title: Read text from file and style specific words and display in RichTextBox in Windows Forms
body: <p>I'm trying to create as a challenge for myself a text editor with some simple syntax features.(Like display some specific words in bold, different color, etc.).</p>
  
  <p>I'm using Windows forms and Visual C++ and this is what i've done so far:
  - i've opened, read the file in a String^ and displayed it in the RickTextBox;
  - i've managed to style the desired words only with Find() method as seen in the stylewords() method in code sample;</p>
  
  <p>My goal would be to open and read the file in a String^, check and compare each word if it is going to be individually styled and after i have applied the style rules i will load the text in the richTextBox.</p>
  
  <p>/* this is loading the document in the RichTextBox control */</p>
  
  <pre><code>private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
               Stream^ myStream;
               OpenFileDialog^ openFileDialog1=gcnew OpenFileDialog;
               if(openFileDialog1-&gt;ShowDialog()==System::Windows::Forms::DialogResult::OK)
               {
                   if((myStream=openFileDialog1-&gt;OpenFile())!=nullptr)
                   {
                       String^ strfilename=openFileDialog1-&gt;InitialDirectory + openFileDialog1-&gt;FileName;
                       String^ Readfile=File::ReadAllText(strfilename);
                       //MessageBox::Show(strfilename);
                       richTextBox1-&gt;Text=Readfile;
                       myStream-&gt;Close();
                   }
               }
               stylewords(); //call method to style words
           }
  </code></pre>
  
  <p>I know i can use the Find() method to search for a specific word and apply a style to it but from what i know this works searching the whole string for that exact word and if i want to style let's say another 10 more different words i must do that over and over again....</p>
  
  <pre><code>void stylewords(){
  int index=0;
  while (index&lt;richTextBox1-&gt;Text-&gt;LastIndexOf(textBox1-&gt;Text)) {
      richTextBox1-&gt;Find("abcdef", index, richTextBox1-&gt;TextLength, RichTextBoxFinds::WholeWord);
      richTextBox1-&gt;SelectionFont=gcnew System::Drawing::Font("Tahoma", 16, FontStyle::Italic);
      richTextBox1-&gt;SelectionColor=Color::DarkBlue;
      richTextBox1-&gt;Find("xyz", index, richTextBox1-&gt;TextLength, RichTextBoxFinds::WholeWord);
      richTextBox1-&gt;SelectionFont=gcnew System::Drawing::Font("Tahoma", 16, FontStyle::Bold);
      richTextBox1-&gt;SelectionColor=Color::DarkOrange;
      index=richTextBox1-&gt;Text-&gt;IndexOf(textBox1-&gt;Text,index)+1;       
  }}
  </code></pre>
  
  <p>Feel free to give advice or point me in the right direction ! 
  Thank you in advance !</p>