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

Posted on 2007-10-10
Last Modified: 2013-12-17
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,
Question by:DeniseGoodheart
    LVL 21

    Accepted Solution

    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?

    Author Comment

    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)


    Author Comment

    Also I changed color.yellow to yellow to make it work.
    LVL 11

    Expert Comment

    Imports System.Drawing

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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now