Color issue

mentalhard

Well-known member
Joined
Aug 7, 2006
Messages
123
Programming Experience
Beginner
VB.NET:
dim s as string = System.Drawing.ColorTranslator.ToHtml(Me.BackColor)
returns color values in a html format and that's fine but when this.BackColor is a KnownColor it returns the name of the color like Red, Blue etc.

My question is how do i avoid this issue and make it that always returns the color in a html format e.g. "#ccffcc"

Thanks :)
 
Last edited by a moderator:
Why is the known color name an issue? It is a valid html color value.

Oh, almost forgot, this site (VB.Net Forums) is for VB.Net language only.
 
Just remove that semicolon and replace this with "Me" and voila it's a pure VB.NET.
However known name is a valid color value indeed but not when you need to proceed a HTML string to ShockWaveFlash object backColor. It accepts only "#xxxxxx" format.

Correct me if i am wrong!?

Thanks
 
Ok, that is nice to hear, I have corrected the code in your post.

You are probably right ShockWave doesn't know color names, however it is easy to get the hex value, translate the color to Win32 integer and use ToString to format the integer as hex:
VB.NET:
Dim hexformat As String = "#" & ColorTranslator.ToWin32(Color.Blue).ToString("X")
 
Back
Top