I am using Delphi 2010 and if I create a new VCL application, drop a TPanel on the form and set its "color" property to "clInactiveCaptionText" it shows the correct color.
Correct color:
However, if I enter the hex value for this color ($00434E54 --- R 67,G 78,B 84) it shows up incorrectly. I should note that the result is the same whether I enable runtime themes or not.
Wrong color:
Any idea on why it won't correctly show this color when specifying its hex value?
A hexadecimal color is specified with: #RRGGBB, where the RR (red), GG (green) and BB (blue) hexadecimal integers specify the components of the color.
Hex color codes start with a pound sign or hashtag (#) and are followed by six letters and/or numbers. The first two letters/numbers refer to red, the next two refer to green, and the last two refer to blue. The color values are defined in values between 00 and FF (instead of from 0 to 255 in RGB).
There is no informational difference between RGB and HEX colors; they are simply different ways of communicating the same thing – a red, green, and blue color value.
The most common way to specify colors in CSS is to use their hexadecimal (or hex) values. Hex values are actually just a different way to represent RGB values. Instead of using three numbers between 0 and 255, you use six hexadecimal numbers. Hex numbers can be 0-9 and A-F.
RGB color values are actually specified as BGR.
So if you want:
As others have indicated, the RGB values are stored internally as BGR (i.e. TColor
value, or what Windows calls a COLORREF
), that's why when you specify a custom color code you obtain a different color.
To maintain your sanity when specifying colors in RGB form you can use the RGB() function from the Windows unit; this accepts parameters in the "natural"/intuitive RGB order (as byte values) and yields an appropriate TColor
/ COLORREF
value:
MyPanel.Color := RGB(67, 78, 84);
or if hex is easier:
MyPanel.Color := RGB($43, $4E, $54);
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