0

I am trying to get a hex color using c# in ASp .net with the following code:

 System.Windows.Media.Color color = (Color)System.Windows.Media
                                                 .ColorConverter            
                                                 .ConvertFromString("##009999");
 Calendar1.BackColor = color;

and I get the following error:

Error 6 Cannot implicitly convert type 'System.Windows.Media.Color'

to 'System.Drawing.Color.

Any Help?

Community
  • 1
  • 1
pikk
  • 837
  • 5
  • 21
  • 38
  • IF you need a System.Drawing.Color is there any reason you are going via a System.Windows.Media.Color? It looks like you have a pretty standard hex color string that could be converted to a Color directly I'd have thought... (via code like `System.Drawing.ColorTranslator.FromHtml("#FFCC66")`;) – Chris Mar 07 '12 at 09:52
  • Media.Color to Drawing-Color: http://stackoverflow.com/questions/4615779/converting-system-windows-media-color-to-system-drawing-color – Tim Schmelter Mar 07 '12 at 09:53

1 Answers1

3

In fact on rereading the question again I think this is the answer:

System.Drawing.ColorTranslator.FromHtml("#009999")

Note that you only want one # in the input string (so you may need to prune if your input has two).

This will give you a System.Drawing.Color which looks like it is what you want without worrying about System.Windows.Media.Color

Chris
  • 27,210
  • 6
  • 71
  • 92