Results 1 to 2 of 2

Thread: WPF save colors to database

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2012

    WPF save colors to database

    I've been trying to figure out how to handle brushes in WPF. I want to let the user configure the colors they like and save that in a database which I've more or less figured out how to do (use solidcolorbrushes then cast that to a color and toostring gives me the value which I can save as VARCHAR in an accdb.

    What I haven't been able to decipher is how to go from a string like #FFE2F2EF to a color and then a solidbrush. Seems winforms has simple ways but I can't find anything for WPF.

    Of course there is probably a simple method that I just can't seem to find.

    Anyone have any ideas?

  2. #2
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011

    Re: WPF save colors to database

    WPF is annoying like that with simple ways of doing thing just overlooked so we have to do it ourselves. Here is a function that could convert that String into a Color:-
        Private Function GetColor(ByVal colorStr As String) As Color
            Dim c As UInteger = Convert.ToUInt32(colorStr.Substring(1), 16)
            Dim A, R, G, B As Byte
            B = c And &HFFI
            G = (c And (&HFFI << 8)) >> 8
            R = (c And (&HFFI << 16)) >> 16
            A = (c And (&HFFI << 24)) >> 24
            Return Color.FromArgb(A, R, G, B)
        End Function
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width