Results 1 to 2 of 2

Thread: [RESOLVED] Typecast String to System.Drawing.Color?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2007
    Posts
    70

    Resolved [RESOLVED] Typecast String to System.Drawing.Color?

    Say I had a string

    Dim s as string = "Color.Black"

    Is there a way to typecast it into a System.Drawing.Color if it is the exact name of a real color in it?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Typecast String to System.Drawing.Color?

    You can't cast because casting doesn't change the type of the object. You are changing the type of the object, so you're converting, not casting. To do that you should look at the Color.FromName method. As the doco says:
    Valid names are the same as the names of the elements of the KnownColor enumeration.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width