• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1209
  • Last Modified:

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
0
DeniseGoodheart
Asked:
DeniseGoodheart
  • 2
1 Solution
 
surajgupthaCommented:
Thats right. It wouldnt work as long as you used string. you will have to change the property to type color instead of type string

But can you explain what you are trying to do?
0
 
DeniseGoodheartAuthor Commented:
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
0
 
DeniseGoodheartAuthor Commented:
Also I changed color.yellow to yellow to make it work.
0
 
AkisCCommented:
-use-
Imports System.Drawing

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

0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now