Link to home
Start Free TrialLog in
Avatar of DeniseGoodheart
DeniseGoodheart

asked on

Value of type string cannot be converted to System.Drawing.Color Error

Good Day:

I created a VB.NET 2005 color template form that allows the user to select a color to be used for the form text controls.  The value is stored in the Public Property UserProfileColorGet() As String.  For example, the user selects color A which equals color.yellow.  My problem is the following code gives me an error that reads: Value of type string cannot be converted to System.Drawing.Color

Private Sub txtSO_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSO.Leave
        Dim sColor As String = oCon.UserProfileColorGet
        Me.txtSO.BackColor = sColor
    End Sub

How can I fix this problem?

Thank You,
Denise
ASKER CERTIFIED SOLUTION
Avatar of surajguptha
surajguptha
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of DeniseGoodheart
DeniseGoodheart

ASKER

Hello surajguptha:

Thank you for offering to help me.  You get an easy 500 points because I figured out the solution as follows:
       txtSO.BackColor = System.Drawing.Color.FromName(sColor)

Cheers,
Denise
Also I changed color.yellow to yellow to make it work.
Avatar of AkisC
-use-
Imports System.Drawing

-then replace your line-
Me.txtSO.BackColor = sColor
-with-
Me.txtSO.BackColor = Color.FromName(sColor)