I am trying to convert VB6 windows forms to VB.NET forms. Now the issue is about the Color conversion. In VB6 colors codes are like HH00400040 ,H00000000 ,etc. How to convert these codes to color options available for VB.NET.Not getting any idea on these.
-
https://msdn.microsoft.com/en-us/library/system.drawing.color.fromargb%28v=vs.110%29.aspx – Hans Passant Apr 17 '16 at 12:42
-
1http://stackoverflow.com/questions/13356486/convert-hex-color-string-to-rgb-color – Abdellah OUMGHAR Apr 17 '16 at 13:04
3 Answers
VB6 stores RGB color in an Int32 and assigns first byte for Blue, second for green and third for red. so you can convert int32 to bytes and use appropriate byte for rgb colors as arguments.
or easily use Color.FromArgb(Integer)
method.

- 1,081
- 9
- 10
I have a SQL server database with colors in a integer variable, stored by vb6. If you want to use the same color codes, you could use:
Color.FromArgb(c Mod 256, c \ 256 Mod 256, c \ 256 ^ 2 Mod 256)
c is the integer color variable. Color.FromArgb(c)
do not work
If you want to put it back in the table you could use:
c = Color.R + Color.G*256 + Color.B*256^2

- 78
- 8
Although your question states that you are using "VB.NET forms" which is probably WinForms, here's a solution for people trying to do the same using WPF. You can convert a VB6 code like &H00FBBE88&
to XAML by:
- Dropping the front
&H00
. - Dropping the
&
at the end. - Swapping first two digits with the last two, as explained in mehrdad safa's answer.
- Adding
#
in front of the string.
The resulting code would be #88BEFB
. Used in a Border, it would look like this:
<Border Background="#88BEFB">
</Border>

- 4,697
- 5
- 13
- 29