RichTextBlock bold effect on specified text range

577 Views Asked by At

Can I make a bold effect on specified text in a RichTextBlock?

Example RichTextBlock content:

It allows you to make some unknown jobs quickly

I should make a bold effect on the word "unknown" so it should look like:

It allows you to make some unknown jobs quickly

I can add linebreak with UNICODE characters. It is "\u2028". Is there any code to make bold effect with UNICODE?

2

There are 2 best solutions below

3
On

Yes, you can add text effects for any range of characters that you want. Here is a code snippet in VB.net - sorry I don't do c#.

One way is to change the current font before you append new text:

rtbEmail.SelectionFont = New Font(rtbEmail.Font.Name, CSng(rtbEmail.Font.Size * 1.25))
rtbEmail.AppendText("To: " & emailparts.ToData & vbCrLf & "From: " & emailparts.FromData & vbCrLf & "Subject: " & emailparts.SubjectData & vbCrLf)

Another way is to define a beginning and end of a range of text:

highlightstart = rtbEmail.TextLength
rtbEmail.AppendText(msg.Message)
rtbEmail.SelectionStart = highlightstart
rtbEmail.SelectionLength = rtbEmail.TextLength - highlightstart
rtbEmail.SelectionFont = New Font("Courier New", rtbEmail.Font.Size, FontStyle.Regular)

HTH - Ken

1
On

According to the source below, you can insert <Bold> tags to format your text.

Try the following in your XAML document and see if it works:

It allows you to make some <Bold>unknown</Bold> jobs quickly

Source: http://msdn.microsoft.com/en-us/library/aa970779.aspx