title: How can I change the selected text background color in Rich text box wpf c#
body: <p>How can I display html text in to <code>RichTextBox</code> control?</p>
  
  <p>Actually I want to change the selected text background color in <code>RichTextBox</code> in C# wpf. I tried this code but it's not displaying formatted text.</p>
  
  <p>Please help me... Thanks in advance!</p>
  
  <pre><code>void rtbTextEditor_SelectionChanged(object sender, RoutedEventArgs e)
  {
      SelectionText = rtbTextEditor.Selection.Text.Trim();
      if (SelectionText != string.Empty)
      {
          if (VisualEditor.Document.Body != null)
          {
               //VisualEditor is web browser
               VisualEditor.Document.Body.InnerHtml = @"""&lt;html&gt;&lt;body&gt;&lt;FONT style=""BACKGROUND-COLOR: #ffff00""&gt;&lt;bold&gt;""" + rtbTextEditor.Selection.Text + @"""&lt;/Bold&gt;&lt;/FONT&gt;&lt;/body&gt;&lt;/html&gt;""";
               VisualEditor.Document.ExecCommand("SelectAll", false, null);
               rtbTextEditor.Document.Blocks.Add(new Paragraph(new Run(VisualEditor.Document.Body.InnerText.ToString())));
          }
      }
  }
  </code></pre>