[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5331
  • Last Modified:

Bold or italic charecter in RichTextBox or RTF

I have a RichTextBox. I'm assigning the Text like;
          myRichTextBox.Text =
                    "Welcome," + Session["Name"] + Environment.NewLine
                    + "Your Age is " + Session["Age"];
Everything is ok. The Text shown as;

Welcome, Kosturdur
Your Age is 30

But how can I make the words "Kosturdur" and "30" bold or colored while assigning the value. I know that it's impossibe to do it with Text property so I have to use RTF property of RichTextBox
(RichTextBox.RTF =....).
The problem is I don't know can I do it. I tried but couldn't successed.

1 Solution
Wayne Taylor (webtubbs)AstronautCommented:
You don't need to use the RTF property. You can simply modify the SelectionFont property when required.....
        myRichTextBox.SelectedText = "Welcome, ";
        myRichTextBox.SelectionFont = new Font(myRichTextBox.Font, FontStyle.Bold);
        myRichTextBox.SelectedText = Session["Name"] + Environment.NewLine;
        myRichTextBox.SelectionFont = new Font(myRichTextBox.Font, FontStyle.Regular);
        myRichTextBox.SelectedText = "Your Age is ";
        myRichTextBox.SelectionFont = new Font(myRichTextBox.Font, FontStyle.Bold);
        myRichTextBox.SelectedText = Session["Age"];

Open in new window

kosturdurAuthor Commented:
Thanks webtubbs,
it works great

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now