tags:

views:

485

answers:

6

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#?

+1  A: 

You can't format the text inside a Label. However, you could use a RichTextBox and make it look like a Label...

Julien Poulin
+2  A: 

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.

Thorsten Dittmar
A: 

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.

Ksempac
+1  A: 

Instead of using a Label, you could try using a RichTextBox and make it non-editable.

Mark Seemann
+1  A: 

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.

Rune Grimstad