• behance
  • gitHub
  • google
  • linkedin
  • twitter
WPF Hex to Brush Conversion

WPF Hex to Brush Conversion

I recently found myself needing to do this and it took longer than expected! Anyway here is my solution!

[source:c-sharp] BrushConverter bc = new BrushConverter();
Brush brush;
brush = (Brush)bc.ConvertFrom(ci.Colour);
txtSetterColor.Background = brush;
[/source]

4 Comments

  1. avatar
    Trevor · November 5, 2008 Reply

    txtSetterColor.Background = (Brush)new BrushConverter().ConvertFrom(ci.Colour);

  2. avatar
    Jammer · November 6, 2008 Reply

    Indeedy! Nice …

  3. avatar
    Goblin · November 25, 2009 Reply

    Brush myBrush;
    myBrush = new SolidColorBrush ( Color.FromArgb ( 255, 255, 0, 0 ) );

    This one works too.

    Or the fastest way:

    myTextBox.Foreground = new SolidColorBrush ( Color.FromArgb ( 255, 255, 0, 0 ) );
    myTextBox.Background = new SolidColorBrush ( Color.FromArgb ( 255, 0, 255, 0 ) );

    Happy Coding

  4. avatar
    Kobe Bryant shoes · April 21, 2010 Reply

    Took me time to read all the comments, but I really enjoyed the article. It proved to be very useful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also entertained! I’m sure you had joy writing this article.

Leave a reply

*