From: Dmitriy Antonov on

"Larry Serflaten" <serflaten(a)usinternet.com> wrote in message
news:eLhxxKF5GHA.668(a)TK2MSFTNGP02.phx.gbl...
>
> "Jim Y" <jj819stuffNOSPAM(a)comcast.net> wrote
>> For example, for the light red, it requires the RGB values of 255, 224,
>> 224 which correspond
>> (close, not exact) to the hexadecimal values of C0C0FF. How do I obtain
>> 224 from C0? 255 from FF?
>> If I remember, C is 13 and 0 is 10, F is 15.
>
> Form1.BackColor = &HC0C0FF
> Form1.BackColor = RGB(&HFF, &HC0, &HC0)
> Form1.BackColor = RGB(255, 224, 224)
>
> These three statements produce the exact same color. You already
> have the hex values, so use them in your calls. Unless you need
> to send text, hex and decimal values are equivalent / interchangeable.
>
> In the Hex notation, the order is BBGGRR
> In the RGB function, the order is RR, GG, BB
>
> Experiment with it a little, it is not difficult....
>
> LFS
>
>

?RGB(&HFF, &HC0, &HC0)
12632319
?RGB(255, 224, 224)
14737663


&HC0 is equal to 192, so correct equivalent should be

?RGB(255, 192, 192)
12632319

Dmitriy.


From: Larry Serflaten on

"Dmitriy Antonov" <antonovdima(a)netzero.net_NOT_FOR_SPAM> wrote

> > Form1.BackColor = &HC0C0FF
> > Form1.BackColor = RGB(&HFF, &HC0, &HC0)
> > Form1.BackColor = RGB(255, 224, 224)
> >
> > These three statements produce the exact same color.

Thanks Dmitriy, I should have tested that. I took the OP at
his word that those were the correct values.


> &HC0 is equal to 192, so correct equivalent should be
>
> ?RGB(255, 192, 192)
> 12632319


I stand corrected...

LFS


From: Dmitriy Antonov on

"Larry Serflaten" <serflaten(a)usinternet.com> wrote in message
news:uQsxhVF5GHA.4996(a)TK2MSFTNGP04.phx.gbl...
>
> "Dmitriy Antonov" <antonovdima(a)netzero.net_NOT_FOR_SPAM> wrote
>
>> > Form1.BackColor = &HC0C0FF
>> > Form1.BackColor = RGB(&HFF, &HC0, &HC0)
>> > Form1.BackColor = RGB(255, 224, 224)
>> >
>> > These three statements produce the exact same color.
>
> Thanks Dmitriy, I should have tested that. I took the OP at
> his word that those were the correct values.

Jim was so insisting on that equivalency that you decided: "Let it be" <g>

Dmitriy.


From: Michael C on
"Jim Y" <jj819stuffNOSPAM(a)comcast.net> wrote in message
news:uYCdndgesrWERYDYnZ2dnUVZ_v6dnZ2d(a)comcast.com...
> VB6 uses hexadecimals to define color of forms and text. Is there a
> program or some way that I can obtain the following for these 4 colors?
>
> Light Blue = &H00FFFFC0&
> Light Yellow = &H00C0FFFF&
> Light Red = &H00C0C0FF&
> Light Green = &H00C0FFC0&
>
> I need the Hue, Sat, Lum, Red, Green and Blue numerical values of each
> color.
>
> I am creating some small graphics and want to color match the background
> when the graphic is placed on an Image Control. Consider the graphic to
> be a silver oval in a rectangle. Unfortunately, I cannot make the
> background transparent with the software that I am using. I would prefer
> a method that will permit me to use any color in the future.

Here's how to get a color from hue, saturation and luminance in c#.
Unfortunately I don't have code to convert an RGB color to HSL because c#
has built in functionality for this. This should be pretty straight forward
to translate to VB. You can consider HSL to be a type with member called Hue
Saturation and Luminance each defined as single (float in c#).

public static explicit operator Color(HSL Value)
{
float r, g, b;
if (Value.Saturation == 0)
{
// gray values
r = g = b = Value.Luminance;
}
else
{
float v1, v2;

v2 = (Value.Luminance < 0.5f) ? (Value.Luminance * (1 +
Value.Saturation)) : ((Value.Luminance + Value.Saturation) -
(Value.Luminance * Value.Saturation));
v1 = 2f * Value.Luminance - v2;

r = HueToRGB(v1, v2, Value.Hue + (1.0f / 3));
g = HueToRGB(v1, v2, Value.Hue);
b = HueToRGB(v1, v2, Value.Hue - (1.0f / 3));
}
return Color.FromArgb(Value.Alpha, RoundIt(r), RoundIt(g), RoundIt(b));
}

private static float HueToRGB(float v1, float v2, float vH)
{
if(vH < 0f) vH += 1f;
if(vH > 1f) vH -= 1f;
if(6f * vH < 1f) return (v1 + (v2 - v1) * 6f * vH);
if((2f * vH) < 1f) return v2;
if((3f * vH) < 2f) return (v1 + (v2 - v1) * ((2.0f / 3f) - vH) * 6f);
return v1;
}

private static int RoundIt(float Value)
{
return (int)Math.Round(Value * 255.0, 0);
}

>
> Thank you,
> Jim Y
>
>


From: Sneha Menon on

Jim Y wrote:

> How do I get the color value? I have the hex value.
>
> Jim Y
> >
--------------------------------------------------------------------------------------
Hi Jim

This is something dug out of my learning-vb time files.
Havent modified or optimized thereafter.

Anyway this will suit your need.

Put 4 Text boxes and command button on a form
Enter Hex value in Text1 and press the button

You will get the RGB values in the other

--------------Code-------------------------------

Private Sub Command1_Click()
Dim k, rH, rR, rG, rB, HeStr, thisCh

HeStr = "0123456789ABCDEF"
rH = UCase(Text1.Text)
For k = 1 To 6
thisCh = Mid(rH, k, 1)
If InStr(HeStr, thisCh) < 1 Then
MsgBox ("Invalid Characters in the Hex field!")
Else

rR = (((InStr(1, HeStr, Mid(rH, 1, 1)) - 1) * 16)) + (InStr(1, HeStr,
Mid(rH, 2, 1)) - 1)
rG = (((InStr(1, HeStr, Mid(rH, 3, 1)) - 1) * 16)) + (InStr(1, HeStr,
Mid(rH, 4, 1)) - 1)
rB = (((InStr(1, HeStr, Mid(rH, 5, 1)) - 1) * 16)) + (InStr(1, HeStr,
Mid(rH, 5, 1)) - 1)

Text2.Text = rR 'Red value
Text3.Text = rG 'Green value
Text4.Text = rB 'Blue
End If
Next k

End Sub
----------------------------Code End------------------

Let me know whether it solved your problem

Regards

Sneha
---------------------------------------------------------------------------------------

First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5 6 7 8
Prev: VB application to AS400 Emulator
Next: Vb6 Project won't load