Library code snippets

VB Express Color Object to Hex String

Code

This function takes a color object and returns the Hex value with a preceeding #.

Private Function ColorHex( ByVal color As Color) As String
        Dim r As String = Hex(FColor.R), G As String = Hex(FColor.G), B As String = Hex(FColor.B)
        If r.Length = 1 Then r = 0 & r : If G.Length = 1 Then G = 0 & G : If B.Length = 1 Then B = 0 & B
        ColorHex = "#" & r & G & B
End Function

Comments

  1. 14 Sep 2006 at 11:18

    Yes, that gives you am html compatible string, or if you want the Hex version just do:

    "#" + System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Green).ToString("X6")

     

  2. 01 Jul 2006 at 20:49

    In VB Express can you not use

    Imports System.Drawing.ColorTranslator

    Then just code

    txtHtmlName.Text = ToHtml(cPreview.BackColor)

    txtHtmlName.Text = Drawing.ColorTranslator.ToHtml(cPreview.BackColor)

    Back to a color

    cPreview.BackColor = Drawing.ColorTranslator.FromHtml(txtHtmlName.Text)

    There are lots of color functions but I had to spend a lot of time finding good examples

    Like

    Imports System.Drawing.Color

    cPreview.BackColor = FromArgb(c.Red, c.Green, c.Blue)

    Just thought I would share these

    David

  3. 01 Jan 1999 at 00:00

    This thread is for discussions of VB Express Color Object to Hex String.

Leave a comment

Sign in or Join us (it's free).

Chris Buske
AddThis

Related podcasts

  • xpert to Expert: Inside Concurrent Basic (CB)

    "Concurrent Basic extends Visual Basic with stylish asynchronous concurrency constructs derived from the join calculus. Our design advances earlier MSRC work on Polyphonic C#, Comega and the Joins Library. Unlike its C# based predecessors, CB adopts a simple event-like syntax familiar to VB progr...

We'd love to hear what you think! Submit ideas or give us feedback