Click here to Skip to main content
15,885,896 members
Articles / Desktop Programming / WPF

WPF Color Palette Control

Rate me:
Please Sign up or sign in to vote.
4.90/5 (25 votes)
19 Feb 2008CPOL2 min read 75K   718   20  
A color palette user control developed using WPF
Public Class Form1
    Dim col As Color
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ColorPalette1.PaletteHeight = 100
        ColorPalette1.PaletteWidth = 360
        AddHandler ColorPalette1.ColorPaletteMouseMove, AddressOf ColorPalette1_MouseMove
        AddHandler ColorPalette1.ColorPaletteSelect, AddressOf ColorPalette1_MouseLeftClick

        col = Panel1.BackColor
    End Sub

    Private Sub ColorPalette1_MouseLeftClick(ByVal sender As System.Object, ByVal c As System.Windows.Media.Color)

        Panel1.BackColor = System.Drawing.Color.FromArgb(255, Convert.ToInt32(c.R.ToString()), Convert.ToInt32(c.G.ToString()), Convert.ToInt32(c.B.ToString()))


    End Sub

    Private Sub ColorPalette1_MouseMove(ByVal sender As System.Object, ByVal c As System.Windows.Media.Color)
        If (c = Nothing) Then
            Panel1.BackColor = col
            SetValues(col.R, col.G, col.B)
        Else
            Panel1.BackColor = System.Drawing.Color.FromArgb(255, Convert.ToInt32(c.R.ToString()), Convert.ToInt32(c.G.ToString()), Convert.ToInt32(c.B.ToString()))
            SetValues(c.R, c.G, c.B)
        End If


    End Sub

    Private Sub SetValues(ByVal r As String, ByVal g As String, ByVal b As String)
        txtRed.Text = r
        txtGreen.Text = g
        txtBlue.Text = b
    End Sub
End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Proteans Software Solutions, Bangalore
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions