Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does TPanel's color property display the wrong color when using a hex color value?

Tags:

delphi

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:

enter image description here

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:

enter image description here

Any idea on why it won't correctly show this color when specifying its hex value?

like image 293
Mick Avatar asked Oct 04 '11 18:10

Mick


People also ask

How do you write the colors when using the hex in CSS?

A hexadecimal color is specified with: #RRGGBB, where the RR (red), GG (green) and BB (blue) hexadecimal integers specify the components of the color.

How do I change the color of a hex code?

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).

Is RGB more accurate than hex?

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.

How hex and RGB color is used in CSS?

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.


2 Answers

RGB color values are actually specified as BGR.

So if you want:

  • red you need to specify $000000FF
  • green you need to specify $0000FF00
  • blue you need to specify $00FF0000
like image 90
Marjan Venema Avatar answered Sep 21 '22 12:09

Marjan Venema


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);
like image 27
Deltics Avatar answered Sep 19 '22 12:09

Deltics