PC Review


Reply
Thread Tools Rate Thread

Color Definition

 
 
Paul W Smith
Guest
Posts: n/a
 
      28th Apr 2010
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?


 
Reply With Quote
 
 
 
 
Peter T
Guest
Posts: n/a
 
      28th Apr 2010
See your other post

"Paul W Smith" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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?
>



 
Reply With Quote
 
Helmut Meukel
Guest
Posts: n/a
 
      28th Apr 2010
"Paul W Smith" <(E-Mail Removed)> schrieb im Newsbeitrag
news:(E-Mail Removed)...
> 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.





 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      29th Apr 2010
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "Paul W Smith" <(E-Mail Removed)> schrieb im Newsbeitrag
> news:(E-Mail Removed)...
>> 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.
>
>
>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Definition Update for Windows Defender - KB915597 (Definition 1.3. Sheesheeb Windows XP Security 3 24th Nov 2009 06:21 PM
Definition Update for Windows Defender-KB91557 (Definition 1.49.52 Adrienne Spyware Announcements 10 17th Dec 2008 01:57 PM
film loses color and definition when put to file =?Utf-8?B?anVzdGluIGJyb3du?= Windows XP MovieMaker 1 2nd Oct 2005 01:06 AM
Re: My definition and color bit resets itself. Kelly Windows XP General 0 30th Aug 2003 09:20 AM
Re: My definition and color bit resets itself. Dragonteeth Windows XP General 0 30th Aug 2003 08:03 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:12 PM.