0

hi

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

regards

2
Contributors
1
Reply
3
Views
8 Years
Discussion Span
Last Post by Teme64
0

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
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.