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#?
-
possible duplicate of [Formatting text in WinForm Label](http://stackoverflow.com/questions/11311/formatting-text-in-winform-label) – Jul 31 '12 at 11:14
-
[http://stackoverflow.com/questions/11311/formatting-text-in-winform-label](http://stackoverflow.com/questions/11311/formatting-text-in-winform-label) – Kim Major Jun 22 '09 at 07:58
5 Answers
You can't format the text inside a Label
. However, you could use a RichTextBox
and make it look like a Label
...

- 12,737
- 10
- 51
- 76
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.

- 55,956
- 8
- 91
- 139
Instead of using a Label, you could try using a RichTextBox and make it non-editable.

- 225,310
- 48
- 427
- 736
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.

- 1,842
- 2
- 18
- 23
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.

- 35,612
- 10
- 61
- 76