How to find out hex value of a color using vb.net

 
The following code sample shows how we can get hex value from System.Drawing.Color using vb.net.

In this example we convert R,G and B values in hexadecimal values and in last we concatenate the these values.See below:

    Private Function HexaValue_Color(ByVal TempColor As Color) As String
        Dim r As String = Hex(TempColor.R)
        Dim G As String = Hex(TempColor.G)
        Dim B As String = Hex(TempColor.B)
        If r.Length = 1 Then
            r = 0 & r
        End If
        If G.Length = 1 Then
            G = 0 & G
        End If
        If B.Length = 1 Then
            B = 0 & B
        End If
        HexaValue_Color = "#" & r & G & B
    End Function