VB6 Color From Long - Equivalent in C#

H

Harvey Triana

Hi. Say, in VB6:

Const CLR2 As Long = &HFFF0DC ' light blue
AnyObj.BackColor = CLR2

- How is the equivalent one in C#?

Thanks,
<Harvey Triana />
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Harvey said:
Hi. Say, in VB6:

Const CLR2 As Long = &HFFF0DC ' light blue
AnyObj.BackColor = CLR2

- How is the equivalent one in C#?

Thanks,
<Harvey Triana />

VB6 colors are BBGGRR, while .NET colors are RRGGBB. Also a .NET color
needs a value for the alpha channel, so you can create color from the
code, then create a solid color from that color:

Const colorTwo As Integer = &HDCF0FF
AnyObject.BackColor = Color.FromArgb(255, Color.FromArgb(colorTwo))

You can also create a color from the separate red, green and blue
components. Then you don't have to specify the alpha value:

AnyObject.BackColor = Color.FromArgb(&HDC, &HF0, &HFF)
 
C

Chris Dunaway

Hi. Say, in VB6:

Const CLR2 As Long = &HFFF0DC ' light blue
AnyObj.BackColor = CLR2

- How is the equivalent one in C#?

Thanks,
<Harvey Triana />

Check out Color.FromARGB method.
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Göran Andersson said:
VB6 colors are BBGGRR, while .NET colors are RRGGBB. Also a .NET color
needs a value for the alpha channel, so you can create color from the
code, then create a solid color from that color:

Const colorTwo As Integer = &HDCF0FF
AnyObject.BackColor = Color.FromArgb(255, Color.FromArgb(colorTwo))

You can also create a color from the separate red, green and blue
components. Then you don't have to specify the alpha value:

AnyObject.BackColor = Color.FromArgb(&HDC, &HF0, &HFF)

Sorry, I gave you VB.NET code, here's the equivalent C# code:

const int colorTwo = 0xDCF0FF;
AnyObject.BackColor = Color.FromArgb(255, Color.FromArgb(colorTwo));

and

AnyObject.BackColor = Color.FromArgb(0xDC, 0xF0, 0xFF);
 
H

Harvey Triana

Thanks a lot Göran

<Harvey Triana />


Göran Andersson said:
Sorry, I gave you VB.NET code, here's the equivalent C# code:

const int colorTwo = 0xDCF0FF;
AnyObject.BackColor = Color.FromArgb(255, Color.FromArgb(colorTwo));

and

AnyObject.BackColor = Color.FromArgb(0xDC, 0xF0, 0xFF);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top