I have a system color value stored in a variable e.g. (Color [A=255, R=255, G=128, B=128])

and i would like to assign that to the back color of a form but i keep getting the error:

" Control does not support transparent background colors. "

my code:

formcolor = Color [A=255, R=255, G=128, B=128]

        Dim testcolor As Color

        testcolor = Color.FromName(formcolor)

        Me.BackColor = testcolor

any help appreciated


Color.FromName accepts only predefined known colors like

Dim testcolor As Color
testcolor = Color.FromName("AliceBlue")
Me.BackColor = testcolor

If you have, for some reason, color information in "Color [A=255, R=255, G=128, B=128]" format, you have to parse color component values and use Color.FromArgb. I don't write the parser, but it should go as follows:

formcolor = "Color [A=255, R=255, G=128, B=128]"
Dim A As Integer
Dim R As Integer
Dim G As Integer
Dim B As Integer
' Dummy values so that this code works
A = 255
R = 255
G = 128
B = 128
' Parse formcolor string here to A, R, G and B variables
Dim testcolor As Color
testcolor = Color.FromArgb(A, R, G, B)
Me.BackColor = testcolor