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]
Share

4 Comments

  1. avatar

    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

    Reply

  2. avatar

    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.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.