The windows form that I designed has 1 label. The text of this label changes dynamically depending on what data the user selects. Currently i'm creating a string and assigning it to the label's text property. I need a way to make certain parts of the string that I am creating bold. How can I accomplish this in c#?
views:
485answers:
6You can't format the text inside a Label
. However, you could use a RichTextBox
and make it look like a Label
...
You'll have to create your own label class and draw the text yourself, switching between bold and non-bold font as you need. The standard Label
class does not support multiple font styles.
You can't do it easily. The Font property on a label is for the whole string.
There are two ways to do it :
-You can split your label into two or more labels if the format you want allows this.
-Or you will have to implement your own user control inherited from label.
Instead of using a Label, you could try using a RichTextBox and make it non-editable.
You would need to use a custom control for this. You could either write your own or you can use an existing control. On CodeProject there is a control, GMarkupLabel, that looks good.