Passing BackColor Values Between .NET and VB6 applications

G

Guest

Hi,

Here's my question first and then some information about what my problem is. Anyone know how or have a function/module/class/whatever to convert from argb to rgb?

We have quite a few vb6 applications that are all called from another vb6 application called the navigator. It's kind of like using explorer. Basically we have two "modes" in the navigator. One is test and one is production. When in test the back color is an ugly orange (just to alert the user they're in test mode) and production is just the typical gray. So when the navigator is told to call an application it writes a bunch of properties to a file for the called application to pick up and apply. One of those properties is backcolor. Well colors must be handled quite differently between vb6 and .net.

In the called application (vb6) the code I use to set backcolor is frmParticipants.BackColor = RetrieveProperty("BackColor"). For the orange test mode the value is 33023. Well in .net I can't specify a color that way. When I send that same orange color property to the called program I use Me.BackColor.ToArgb.ToString and that sends a value of -32768 which the vb6 application doesn't like.

Through some more digging I realized that colors from vb.net are stored as argb and in vb6 it's rgb. I don't really understand what the "a" does in argb other than cause me a headache :-/. I do not want to have to go into each vb6 application and make any changes to convert from argb to rgb so I need to do this on the .net side. Anyone know how or have a function/module/class/whatever to convert from argb to rgb? I guess that's my question in a nutshell.

Thanks,

Jesse
 
S

Sven Groot

Jesse said:
Hi,

Here's my question first and then some information about what my
problem is. Anyone know how or have a function/module/class/whatever
to convert from argb to rgb?

I don't have VB6 here so I can't check, but from the value you give it
appears the order in VB6 is actually BGR, not RGB! This figures
because -32768 in two's complement is FFFF8000 hex, but 33023 is 0080FF hex.
(on a side note, long live the Windows Calculator)

In any case, the alpha value is transparancy. A value of FF (255) is
completely opaque. The only way to solve this is to construct the VB6 number
yourself. If you have a variable C of type Color you can do this as follows:
Dim BGR as Integer
BGR = (C.B << 16) + (C.G << 8) + C.R

The otherway around is of course just reversing the above formula, using
bitwise and to get rid of the unnecessary bits where needed.
C.B = BGR >> 16
C.G = BGR >> 8 And &hff
C.R = BGR And &hff

Hope this helps.
 
C

Chris Haas

Even easier, you can go from VB6 to VB.Net using:

System.Drawing.ColorTranslator.FromOle()

It takes an Int32 and return a Color
 
G

Guest

Thanks Chris. That's the easiest way that I've found. I just did System.Drawing.ColorTranslator.ToOle(Me.BackColor).ToString to convert the .net backcolor to a color that vb6 likes. So now as I convert all of those vb6 apps to .net I'm going to have to do me.backcolor = System.Drawing.ColorTranslator.FromOle(IntColorPassedIn). Then once all my vb6 apps are converted then I can just pass the colors across without any converting.

Jesse
 

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