Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Convert string to KnownColor?

5 views
Skip to first unread message

mianiro

unread,
Apr 5, 2007, 4:12:03 PM4/5/07
to
I have a piece of code that is trying to convert a string to a
knownColor via CType. Is this not possible? I keep getting an error
that you cant convert a string to an integer. Is there another way to
do this?

For Each clr as object In Colors
If Not Color.FromKnownColor(CType(clr,
KnownColor)).IsSystemColor Then
alColor.Add(clr.ToString)
End If
Next


Thanks so much.

Mattias Sjögren

unread,
Apr 5, 2007, 5:40:38 PM4/5/07
to

>Is there another way to do this?

System.Enum.Parse


Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

mianiro

unread,
Apr 6, 2007, 7:38:15 AM4/6/07
to
On Apr 5, 5:40 pm, Mattias Sjögren <mattias.dont.want.s...@mvps.org>
wrote:

> >Is there another way to do this?
>
> System.Enum.Parse
>
> Mattias
>
> --
> Mattias Sjögren [C# MVP] mattias @ mvps.orghttp://www.msjogren.net/dotnet/|http://www.dotnetinterop.com

> Please reply only to the newsgroup.

Thank you so much!

kiranraveendranath

unread,
Nov 16, 2009, 6:45:15 AM11/16/09
to
Yes, Enum.Parse();

-----------------------------------------v
Giving sample for someone to use in future.

KnownColor kc=(KnownColor) Enum.Parse(typeof(KnownColor), "White", true);

mianiro wrote:

Convert string to KnownColor?
05-Apr-07


Thanks so much.

Previous Posts In This Thread:

On Thursday, April 05, 2007 4:12 PM
mianiro wrote:

Convert string to KnownColor?


Thanks so much.

On Thursday, April 05, 2007 5:40 PM
Mattias Sj?gren wrote:

Re: Convert string to KnownColor?
System.Enum.Parse


Mattias

--
Mattias Sj?gren [C# MVP] mattias @ mvps.org

On Friday, April 06, 2007 7:38 AM
mianiro wrote:

Re: Convert string to KnownColor?
wrote:
net/|http://www.dotnetinterop.com

Thank you so much!

EggHeadCafe - Software Developer Portal of Choice
Sum of Numbers Captcha: Keeping it Simple
http://www.eggheadcafe.com/tutorials/aspnet/8eacfaca-3629-4d40-9d83-8eb1c526ca7f/sum-of-numbers-captcha-k.aspx

0 new messages