Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change colour of toolStripLabel C#.Net

I would like to change the colour of the label box - not just the text within the label. How would i do this?

label.BackColor = Color.Coral; (for instance) will change the colour of the text within the label.. rather than the background colour of the entire label box.

Also, if it matters, i'm using a toolStripContainer and ToolStrip. I used ToolStrip to create a label.... (i've used ForeColor in my code because using "BackColor" results in no change what so ever. Using ForeColor at least changes the colour of the font)

    private void labelEdit_MouseHover(object sender, EventArgs e)
    {
        labelEdit.ForeColor = Color.Coral;
    }
like image 492
BigBug Avatar asked Feb 23 '23 07:02

BigBug


1 Answers

EDIT: It turns out the question is a bit of a red herring. Changing the ForeColor changes the text appropriately, but changing the BackColor does nothing, apparently.

EDIT: As per comments, it looks like you need to set ToolStrip.RenderMode to ToolStripRenderMode.System on your tool strip.


Now you've posted the actual code, the answer is obvious. You originally said you were using:

label.BackColour = Color.Coral;

You're actually using:

labelFile.ForeColor = Color.Coral;

Note "Fore" vs "Back". You wish to change the background colour... so you should be using

labelFile.BackColor = Color.Coral;
like image 188
Jon Skeet Avatar answered Feb 24 '23 21:02

Jon Skeet