简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM