locked
Convert Color String to Color ? RRS feed

  • Question

  • Hello World 

    i want to convert my color string value to color object. 

    Color String like = #FF25458C

    Please let me know ASAP

    Friday, April 27, 2012 2:12 AM

All replies

  • hi Ravi,

    Try this code ..

                Color c = new Color();
    
                string mycolor = "#FF25458C";
    
                mycolor = mycolor.Substring(1);
                
                byte aVal , rVal , gVal , bVal ; 
                
                if (mycolor.Length == 8)
                {
                    aVal = byte.Parse(mycolor.Substring(0, 2), System.Globalization.NumberStyles.HexNumber);
                    rVal = byte.Parse(mycolor.Substring(2, 4), System.Globalization.NumberStyles.HexNumber);
                    gVal = byte.Parse(mycolor.Substring(4, 6), System.Globalization.NumberStyles.HexNumber);
                    bVal = byte.Parse(mycolor.Substring(6, 8), System.Globalization.NumberStyles.HexNumber);
                    c = Color.FromArgb(aVal, rVal, gVal, bVal);
    
                }  

     Hope it Helps Laughing

    Friday, April 27, 2012 2:55 AM