How Can i Covert String to System.Drawing.Brush

Posted on 2011-10-26
Last Modified: 2012-05-12
How Can i Covert String to System.Drawing.Brush.

what i want to do is like this:
String  colorString = ConfigurationManager.AppSettings["ColorString "];
System.Drawing.Brush  brush;
how can i convert ColorString  to brush?
Question by:HanbingCheng
    LVL 10

    Expert Comment

    maybe by:

    brush = (System.Drawing.Brush)colorString;
    LVL 10

    Expert Comment

    Try this as we;
    // best, using Color's static method Color red1 = Color.FromName("Red");  // using a ColorConverter TypeConverter tc1 = TypeDescriptor.GetConverter(typeof(Color)); // ..or.. TypeConverter tc2 = new ColorConverter(); Color red2 = (Color)tc.ConvertFromString("Red");  // using Reflection on Color or Brush Color red3 = (Color)typeof(Color).GetProperty("Red").GetValue(null, null);  // in WPF you can use a BrushConverter SolidColorBrush redBrush = (SolidColorBrush)new BrushConverter().ConvertFromString("Red");

    Open in new window

    LVL 35

    Accepted Solution

    Assuming is a SolidBrush:

    your code should look like:
    Color customColor = Color.FromName(colorString);
    System.Drawing.Brush  brush = new SolidBrush(customColor);

    Note: your string must be a valid color name ( )

    Author Comment

    We can use like this:
    Brush brush = new SolidBrush(Color.FromName("Red"));

    Author Comment

    I've requested that this question be closed as follows:

    Accepted answer: 0 points for HanbingCheng's comment http:/Q_27417715.html#37142999

    for the following reason:

    find a solution by myself
    LVL 35

    Expert Comment

    by:Miguel Oz
    Your posted solution is the same as mine. You just did it in one and substitute colorString with "Red". My points please

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
    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 is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    728 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

    19 Experts available now in Live!

    Get 1:1 Help Now