I want to create a System.Drawing.Color from a value like #FF00FF or FF00FF without needing to write code for that. There is any .NET built-in parser for that?
views:
506answers:
4
                +4 
                A: 
                
                
              
            You mean like this:
using System.Convert
using System.Drawing
Color yourColor = Color.FromARGB(ToInt32("FF00FF", 16));
                  Bobby
                   2009-12-16 12:58:37
                
              
                +4 
                A: 
                
                
              
            Use the ColorConverter class:
var converter = System.ComponentModel.TypeDescriptor.GetConverter( typeof( Color ) );
color = converter.ConvertFromString( "#FF00FF" );
This can also convert from the standard named colors e.g. ConvertFromString( "Blue" )
See here for a discussion of the standard .NET type conversion mechanisms.
                  Phil Devaney
                   2009-12-16 12:59:34
                
              
                +2 
                A: 
                
                
              
            You can use the System.Drawing.ColorTranslator static method FromHtml.
use:
System.Drawing.ColorTranslator.FromHtml("#FFFFFF");
                  Pat
                   2009-12-16 13:01:05