Here recently I have been working more and more with Visual Studio again, and more specifically the Color Picker / Color Dialog control. For my purposes, I wanted the user to pick a color, and that color to then populate a text box in the form of an HTML compliant hex value, in other words, I need the result from the color picker as a string. Now, in VB.NET 2010 which is what I am using, the result from the color picker is in a format that is primed and ready to apply to a control, to change its fore or back round color. It does not give you a value in string format. So, I had to do a good bit of searching and work to figure this out.
Basically, what I ended up with was a function that you run the color picker response or value through. It’s pretty simple really:
Public Function Color2Html(ByVal MyColor As Color) As String
Return "#" & MyColor.ToArgb().ToString("x").Substring(2).ToUpper
End Function
That’s it, that will return to you a hex color code formatted for HTML use. Just in case you are unsure of exactly how to use the function, this is the code I use with my color picker control (I use a standard button to fire it off with the result going into a text box):
Private Sub btnColor1_Click(sender As System.Object, e As System.EventArgs) Handles btnColor1.Click
Dim NewColor As New ColorDialog()
NewColor.AllowFullOpen = True
NewColor.ShowHelp = True
If (NewColor.ShowDialog() = Windows.Forms.DialogResult.OK) Then
txtColor.Text = Color2Html(NewColor.Color)
End If
End Sub
That’s all there is too it. I hope this helps you get your string data from your Color Dialog / Color Picker control. Enjoy!
I have to share something with everyone now. Anybody and everybody that knows me, knows that I am a die hard UNIX and Linux fan. I made the majority of my career managing UNIX and Linux boxes, with a server to admin ratio of sometimes 100 to 1. Everyone also knows that I am a die hard Debian fan, my distro of choice for my servers and my desktops is Debian, hands down. However, that doesn’t mean that I don’t use or like other distributions, I mean every one has it’s place and purpose. I really dig Ubuntu and SuSE and I cut my teeth on Red Hat and CentOS just as an example.
Just in case you need to know your Internet facing IP address, I have setup a new page just for the purpose of showing you that information and more, right down to your longitude and latitude just in case any of you are hiding some ICBM’s in your backyard and want to reach out and touch someone! So check it out, go to
Are you working on a website? Do you want to do all of the creating and coding of the ‘favicon’ stuff by hand? Heck no, it’s a pain in the rear! No doubt you can do it but it takes a long time and it gets old after you do it a few bazillion times, right? So what’s a poor web developer to do? Well, check out this site: