Set the background to a Hex number

  • Thread starter Thread starter Guest
  • Start date Start date
You can easily do:
this.BackColor = Color.FromArgb(0x00404);

or more explicitly:
this.BackColor = Color.FromArgb(0x00, 0x04, 0x04);

Brendan
 
I was wrong, I took the color from my VB6.0 project, and now I want the color
in my new C# project. The color in VB6.0 is &H00404000&.

The code you provided gives me an error, "This control does not support
transparent background colors." I thought I could use the first 6
characters, but I was wrong. How do I get the same color I had in my VB6
project?
 
Unbeknownst to me, in VB6, colors represented in hex were/are does so in the
order of Blue Green Red, unlike the more typical Red Green Blue.

The color you have specified is 32 bits long, and in VB6 only the lower 24
bits mattered, so your actual color value would be &H404000&, or

40 - Blue
40 - Green
00 - Red

and use my previous code to specify it as:

this.BackColor = Color.FromArgb(0x00, 0x40, 0x40);

Does that work better for you?

Brendan
 
I forgot to mention, if you have more values hex values from VB6 that you
want to use in C#, try the following function, into it you pass your C/C++/C#
hex value (or other numerical value for that matter), and returns an instance
a corresponding Color class.

private Color GetVB6Color(int value)
{
int r, g, b;
r = (value >> 0) & 0xFF;
g = (value >> 8) & 0xFF;
b = (value >> 16) & 0xFF;

return Color.FromArgb(r,g,b);
}

Brendan
 
I took the color from my c# project, and now I want the color
in my new vb 6.0 project.please do help me getting that
 
Back
Top