thoniv
thoniv

Reputation: 79

How to bold a part of string being passed into TextBox in c#

I have a string builder where value is appending at runtime via placeholder. Once string builder has appended, it is assigned to a text box (not rich txt) to show up in UI.

I want part of the text to be bold.

sb.AppendFormat("Added {0} by {1}:\n{2}", DateTime.ToString(), userName, note);
txt.Text = sb.ToString();

Expected output:

Added 9/01/2016 8:47:19 PM by Vinoth: Testing Purpose

How can I achieve this? Is there anyway of looping over words with the : symbol until I want it to be bold?

Upvotes: 0

Views: 827

Answers (1)

ChrisF
ChrisF

Reputation: 137108

You will have to build up the text in sections.

Either as different TextBoxes/TextBlocks or as a single RichTextBox with separate Runs for the sections you want in a different style.

Upvotes: 5

Related Questions