LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Color Definition

Hello Helmut,

A great explanation but just this bit -

To get intermediate shades between a start color and a end
color, split the color value into its red, green and blue values.


Whilst that might work for a very small set of colours the way is do to it
is like this -
RGB to HSL
Then calculate a set of equally spaced L values between 0 to 1 (though 0 & 1
will be black & white), then do
HSL to RGB with the original H & S values and each of the incremented L
values

FWIW, although that approach theoretically returns an equally spaced set of
colour shades they may not be "perceived" as being equally separated. The
human eye doesn't perceive colour and shade differences linearly. It is
possible to devise a subjective 3D "colour space" and work out non linear
colour tone and/or shade differences from the model. But that'll be beyond
the requirements for most typical requirements here.

Regards,
Peter T


"Helmut Meukel" wrote in message
...
"Paul W Smith" schrieb im Newsbeitrag
...
How do I convert a color Long - 8210719, RGB(31,73,125) or #1F49FD to
something I can use to format the backcolor of a form control?

White = &H80000005& - what sort of value is this? How do I convert any
of
the above color references to this format?


Paul,

do you really understand how Windows uses colors?
I don't think so.

Windows is using color constants for various system colors:
Window Background = &H80000005&
Window Text = &H80000008&
Button Face = &H8000000F&
Desktop = &H80000001&
...

These values are always the same regardless of the actual color.
There is an API function to get the actual rgb color for the constant.
If you want a control or a form look on every system like all other
forms/controls, then assign the appropriate color constants to
the color properties. Windows will use this constants and assign
the correct colors to your form/control according to the color
scheme the user has selected.

Color values are usually written as hex numbers.
&H shows VBA the string is really a hex number.

The values for each component go from 0 to 255 (=&HFF).
BTW, joel got it wrong, a RGB value has the components in
reverse order: BBGGRR. Irritating, isn't it?

If you have red, green and blue values of 200, 120 and 60
these are written as hex numbers &HC8, &H78, &H3C
RGB(200, 120, 60) returns 3963080 and
Hex(3963080) returns "3C78C8"
you can code
MyForm.BackColor = 3963080
or
MyForm.BackColor = &H3C78C8&

BTW, the trailing & tells VBA to treat the value as a Long.

To get intermediate shades between a start color and a end
color, split the color value into its red, green and blue values.
Then get the step value for each component:
redstep = (redstart - redend) / numberShades
use Double for the step, not Integer or Long
add the step value to the start value, ...

One thing to add: the human eye may see same step values
different, depending on color and intensity. Usually it can't
see small differences between very dark colors.

I use this Sub to split color values into red green and blue:
Public Sub RGB2RedGreenBlue(ByVal RGBColor As Long, R As Long, G As
Long, B As Long)
R& = RGBColor& And &HFF&
G& = (RGBColor& And &HFF00&) \ &H100&
B& = (RGBColor& And &HFF0000) \ &H10000
End Sub

HTH.

Helmut.







 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Run-Time Error 1004 Application-Definition or Object-Definition Error jparnold Excel Programming 5 December 25th 09 04:33 PM
name definition x taol Excel Programming 2 November 23rd 06 11:52 AM
$ definition nicolebelle Excel Worksheet Functions 1 November 18th 05 01:44 PM
The definition of.... Ursula Excel Worksheet Functions 2 February 16th 05 04:14 PM
Constant definition dee Excel Programming 4 February 13th 05 09:47 PM


All times are GMT +1. The time now is 10:50 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"