Setting Control colors

C

Cliff Lane

I have an application that allows the user to select fore and back ground
colors for command buttons. I use the dialog to select the colors and store
the value returned in the db as a string. For standard colors the db values
are "white" etc. For custom colors the values are "ff808040" etc.

When I try to load these values from the db and set the controls colors I am
getting an error. The statement is
control.forecolor = db.fields("forecolor").value
the error returned is
Specified cast is not Valid.

I have tried using ctype but it then tells me the cast is not allowed.

Am I storing the selected value in the db using the correct type?
How can I set these values

Cliff
 
K

Ken Tucker [MVP]

Hi,

Dim clr As Color =
System.Drawing.ColorTranslator.FromHtml("#FF808040")
Button1.BackColor = clr

Ken
 
S

sterling

Dim SomeColor As System.Drawing.ColorTranslator
Dim myColor = SomeColor.FromHtml(db.fields("forecolor").ToString)
myControl.BackColor = myColor
 

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