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
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With