Home > Net >  System.Drawing.Color named Highlight? What is it? For WinForm
System.Drawing.Color named Highlight? What is it? For WinForm

Time:11-04

I have a WinForm application where this C# code assigns color:

grid.Styles.Highlight.BackColor = Properties.Settings.Default.TrueDBGridSelectedStyleBackColor;

If I look up where it's defined, I find it in Settings.settings defined like so:

<Setting Name="C1TabPageTabBackColorSelected" Type="System.Drawing.Color" Scope="Application">
  <Value Profile="(Default)">Highlight</Value>
</Setting>

Note the word Highlight there. Other colors in this file are defined with a color name or with rgb values, but what does Highlight mean?

If I stop in the debugger on the C# code that assigns it and look at

Properties.Settings.Default.TrueDBGridSelectedStyleBackColor

I see "{Name=Highlight, ARGB=(255, 0, 120, 215)}" System.Drawing.Color

If I assign the same color in ARGB instead like so:

grid.Styles.Highlight.BackColor = Color.FromArgb(255, 0, 120, 215);

I get a different color - much darker blue with no red component in the resulting control.

There is no Color.HighLight constant like there is Color.White for example. What's going on here? Is there some special behaviour for the color named Highlight?

Does it get a color originally from say some OS colors, but gets overwritten by control because of the name? I can't find any doc saying so.

CodePudding user response:

This is most probably the SystemColors.Highlight Property. It does not refer to a specific color but to the highlight color of the current Windows theme used for the background of the selected item, e.g. in a listbox.

As @HansPassant pointed out, Highlight is also one the KnownColor Enum constants. You can use the Color.FromKnownColor(KnownColor) Method to get the color corresponding to an enum constant.

  • Related