Hex Code Viewer *Tutorial*
Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
5 posts
Page 1 of 1
After seeing Clanc789's Hex Code viewer and color creator. I thought it would be a good idea to have a full tutorial on the subject. Turns out, it's not that complicated at all.
- Start by opening up Microsoft Visual Basic, and creating a Windows Forms Application
- In the form, add the following controls:
- Three TrackBars (name them "Red", "Green" and "Blue" + set the Maximum property to "255")
- Three Textboxes (name them "RedValue", "GreenValue" and "BlueValue")
- One PictureBox (name it "Preview")
- One Label (name it "HexCode")
- One Button (change it's text to "Copy")
- One more TextBox (name it "HexCodetb")
- Now, declare the following 3 variables:
Enjoy
-Comathi-
***PLEASE NOTE*** The idea for the Hex Code viewer comes from Clanc789, and some of the codes come from MrAksel and Snyper345. Thank you to all three of them
- Start by opening up Microsoft Visual Basic, and creating a Windows Forms Application
- In the form, add the following controls:
- Three TrackBars (name them "Red", "Green" and "Blue" + set the Maximum property to "255")
- Three Textboxes (name them "RedValue", "GreenValue" and "BlueValue")
- One PictureBox (name it "Preview")
- One Label (name it "HexCode")
- One Button (change it's text to "Copy")
- One more TextBox (name it "HexCodetb")
- Now, declare the following 3 variables:
Code: Select all
- Next, paste the following code for the TrackBars:
Dim R As Integer = 0
Dim B As Integer = 0
Dim G As Integer = 0
Code: Select all
- The following codes go for the TextBoxes:
Private Sub Red_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Red.Scroll
RedValue.Text = Red.Value
End Sub
Private Sub Green_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Green.Scroll
GreenValue.Text = Green.Value
End Sub
Private Sub Blue_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Blue.Scroll
BlueValue.Text = Blue.Value
End Sub
Code: Select all
- Now, add this code for the Button:
Private Sub RedValue_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RedValue.TextChanged
Try
Red.Value = Convert.ToInt32(RedValue.Text)
R = Convert.ToInt32(RedValue.Text)
Preview.BackColor = Color.FromArgb(R, G, B)
Catch ex As Exception
End Try
End Sub
Private Sub GreenValue_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GreenValue.TextChanged
Try
Green.Value = Convert.ToInt32(GreenValue.Text)
G = Convert.ToInt32(GreenValue.Text)
Preview.BackColor = Color.FromArgb(R, G, B)
Catch ex As Exception
End Try
End Sub
Private Sub BlueValue_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BlueValue.TextChanged
Try
Blue.Value = Convert.ToInt32(BlueValue.Text)
B = Convert.ToInt32(BlueValue.Text)
Preview.BackColor = Color.FromArgb(R, G, B)
Catch ex As Exception
End Try
End Sub
Code: Select all
- Finally, add the following for the PictureBox:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
HexCodetb.SelectAll()
HexCodetb.Copy()
End Sub
Code: Select all
- That's it for the code. Now, you can customize the layout of your form. If you want, you can download the file below, which includes the source code to the project. Private Sub Preview_BackColorChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Preview.BackColorChanged
HexCode.Text = ColorTranslator.ToHtml(Preview.BackColor)
HexCodetb.Text = HexCode.Text
End Sub
Enjoy

-Comathi-
***PLEASE NOTE*** The idea for the Hex Code viewer comes from Clanc789, and some of the codes come from MrAksel and Snyper345. Thank you to all three of them

You do not have the required permissions to view the files attached to this post.
You can use this to :
Code: Select all
Here is how to use :Private Function GetHexColor(colorObj as System.Drawing.Color) as String
return "#" & Hex(colorObj.R) & Hex(colorObj.G) & Hex(colorObj.B)
End function
Code: Select all
Me.Text = GetHexColor(Me.BackColor).ToString
comathi wrote:***PLEASE NOTE*** The idea for the Hex Code viewer comes from Clanc789, and some of the codes come from MrAksel and Snyper345. Thank you to all three of themThanks for that

Unbelivable how many hex code viewer tuts/progs are made after my post XD
Practice makes perfect!
VIP since: 6-10-2011
VIP since: 6-10-2011
I guess when someone starts off with a good idea, everyone wants to try it 

5 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023