Convert COLORREF to Color

D

Dan Buck

I would like to convert the COLORREF returned by the
GetThemeColor function to a Color type using C#. I would
appreciate any guidance on the best way to accomplish
this.

Thanks,
Dan
 
M

Mattias Sjögren

Dan,
I would like to convert the COLORREF returned by the
GetThemeColor function to a Color type using C#.

System.Drawing.ColorTranslator.FromWin32(colorrefValue)



Mattias
 
J

Jeremy Cowles

Dan Buck said:
I would like to convert the COLORREF returned by the
GetThemeColor function to a Color type using C#. I would
appreciate any guidance on the best way to accomplish
this.

A color ref is a DWORD (4 bytes) in this format: 0x00bbggrr

Dim ColorRef as Integer
Dim HexColor as String
Dim NetColor as Drawing.Color = Drawing.Color.Blue

HexColor = "&H00"
HexColor += NetColor.B.ToString.PadLeft(2, "0")
HexColor += NetColor.G.ToString.PadLeft(2, "0")
HexColor += NetColor.R.ToString.PadLeft(2, "0")

ColorRef = Val(HexColor)

There is probably an easier way of doing this, but this is the first thing
that came to mind.

HTH,
Jeremy
 

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