[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Casting From String To Color in C#

Posted on 2004-03-31
3
Medium Priority
?
1,930 Views
Last Modified: 2009-04-24
Hi to alll ...
I want to save color in regeistry as a text, But how could I convert it to Color object after retreiving the value from regustry ....
the following code doesn't work
Text.BackColor = ((Color)GetValue(....path.....))

thanks


0
Comment
Question by:programmer_bmb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 4

Expert Comment

by:Jarodtweiss
ID: 10726638
Color is an enumeration and so you can get the corresponding color from the name using that syntax :

String s = "Blue"
Color c = (Color)Enum.Parse(typeof(Color), s);
0
 
LVL 4

Expert Comment

by:Jarodtweiss
ID: 10726646
You may include that in a try catch block as an ArgumentException can be thrown if the provided string is not a correct Color
0
 
LVL 10

Accepted Solution

by:
eternal_21 earned 100 total points
ID: 10726788
Or use the System.Drawing.Color.FromName method, e.g.:

  System.Drawing.Color myColor;
  myColor = System.Drawing.Color.FromName("Blue") ?

Or save an ARGB value represented by an integer in the registry, instead of a string:

  System.Drawing.Color myColor;
  // Choose a color in your application
  // e.g.:
  myColor = System.Drawing.Color.Blue;
  int argbColor = myColor.ToArgb();
  // Save value of argbColor in registry.            

  // Load value from registry.
  int argbColor = _;
  System.Drawing.Color myColor;
  myColor = System.Drawing.Color.FromArgb(argbColor);
  //myColor is now the original color.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

649 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