6

I have label that contain of several strings and one of those string i want to change it color.

This is what i have try:

private string state = string.Empty;
state = System.Drawing.Color.Blue.ToString();

But it still remained to same color

user2214609
  • 4,713
  • 9
  • 34
  • 41

4 Answers4

8

As far as I'm aware, a Windows Forms Label can only use a single color for the whole of its text. If you want multi-colored text, you'll either need to use multiple labels or use RichTextBox... or perform the painting yourself, of course.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
2

You have to change the colour of the label, not the string.

So you'd have a label on your form, say LabelTest, then in your code would look like this:

string state = "Some text for our label";
LabelTest.Text = state;
LabelTest.ForeColor = System.Drawing.Color.Blue;

As has been mentioned in other answers, to use multiple colours, you'd need multiple labels, each with their text and colour set separately.

xen-0
  • 709
  • 4
  • 12
1

Label cannot contain items of more than one color. Use more labels or some other kind of control. But from the code you pasted I recommend to go through some .NET tutorial. You probably miss the basic concepts.

rocky
  • 7,506
  • 3
  • 33
  • 48
0

//this is for label color

Label1.Text.ForeColor = System.Drawing.Color.Red;

//this for textenter code here

Label1.Text.ForeColor = System.Drawing.Color.Red;
Piatoz LP
  • 1
  • 1