5

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;
    }
Nalaka526
  • 11,278
  • 21
  • 82
  • 116
BigBug
  • 6,202
  • 23
  • 87
  • 138
  • 3
    I don't believe that's your actual code, given the use of "Colour" instead of "Color". Please could you post a short but complete program demonstrating the problem? – Jon Skeet Nov 26 '11 at 09:03
  • @Jon Skeet... my canadian-ness accidently happens to spell "color" as "colour" but yea.. my code is pretty much the same - with the exception of the spelling of the word.. – BigBug Nov 26 '11 at 09:10
  • Quite the reverse - I'm glad I asked, because now we've seen that it's not just the spelling of "Color" which is different. It's "fore" vs "back". See my answer. – Jon Skeet Nov 26 '11 at 09:15
  • 1
    This question is probably a duplicate of the one below, which has a potentially better solution: http://stackoverflow.com/questions/8037406/why-doesnt-toolstriplabels-backcolor-property-change-during-design-time-or-run – drwatsoncode Nov 27 '13 at 16:26

1 Answers1

10

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;
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • i've tried using BackColor, but it doesn't change anything at all, hence i put in ForeColor as it at least changes the font colour... – BigBug Nov 26 '11 at 09:18
  • i've noticed that i can change "BackColor" for a button, but not a label... is there a way around this? – BigBug Nov 26 '11 at 09:19
  • 1
    @BlueMonster: Well you should have said that before... if you're going to ask a question saying you're confused as to why the foreground colour is changing, and then you post code changing `ForeColor`, it's not clear what you've tried... – Jon Skeet Nov 26 '11 at 09:19
  • Sure, i'll be more clear in the future... after what i've described, do you know of a solution? – BigBug Nov 26 '11 at 09:21
  • @BlueMonster: Unfortunately not offhand. Will edit my answer to help anyone else looking, but I'm not in a position right now to experiment :( – Jon Skeet Nov 26 '11 at 09:24
  • @Nalaka526 are you using a ToolStripContainer and a ToolStrip label as i mentioned in my Question? – BigBug Nov 26 '11 at 09:40
  • 1
    @BlueMonster: This is why it would be useful if you could show a short but complete program demonstrating the problem :) – Jon Skeet Nov 26 '11 at 09:43
  • Lol, i thought i did? There is no way for me to show you that i'm using a ToolStipContainer as well as a ToolStrip label... is there?... But i did mention it in the Q – BigBug Nov 26 '11 at 09:45
  • 1
    @BlueMonster Sorry, I wasn't using ToolStripContainer.... Add this line before changing the colour, toolStrip2.RenderMode= ToolStripRenderMode.System; This works.!!! – Nalaka526 Nov 26 '11 at 09:59
  • 3
    This where I learnt it from http://social.msdn.microsoft.com/Forums/eu/winforms/thread/de357ebd-5315-4db4-a61d-de8d6a41a8d1 – Nalaka526 Nov 26 '11 at 10:01
  • @BlueMonster Additional info : RenderMode can be changed from properties window – Nalaka526 Nov 26 '11 at 10:19