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
Contributors
User avatar
comathi
Coding God
Coding God
Posts: 1242
Joined: Fri Mar 26, 2010 1:59 pm

Hex Code Viewer *Tutorial*
comathi
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:
Code: Select all
 Dim R As Integer = 0
    Dim B As Integer = 0
    Dim G As Integer = 0
- Next, paste the following code for the TrackBars:
Code: Select all
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
- The following codes go for the TextBoxes:
Code: Select all
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
- Now, add this code for the Button:
Code: Select all
 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        HexCodetb.SelectAll()
        HexCodetb.Copy()
    End Sub
- Finally, add the following for the PictureBox:
Code: Select all
 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
- 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.

Enjoy :D

-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 :D
You do not have the required permissions to view the files attached to this post.
User avatar
Danny
VIP - Donator
VIP - Donator
Posts: 621
Joined: Sat Oct 30, 2010 8:21 pm

Re: Hex Code Viewer *Tutorial*
Danny
wow this is really nice!
User avatar
M1z23R
VIP - Donator
VIP - Donator
Posts: 622
Joined: Tue Sep 28, 2010 4:55 pm

Re: Hex Code Viewer *Tutorial*
M1z23R
You can use this to :
Code: Select all
Private Function GetHexColor(colorObj as System.Drawing.Color) as String
		return "#" & Hex(colorObj.R) & Hex(colorObj.G) & Hex(colorObj.B)
End function
Here is how to use :
Code: Select all
Me.Text = GetHexColor(Me.BackColor).ToString
User avatar
clanc789
Coding Guru
Coding Guru
Posts: 786
Joined: Tue Nov 02, 2010 4:45 pm

Re: Hex Code Viewer *Tutorial*
clanc789
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 them :D
Thanks for that :)

Unbelivable how many hex code viewer tuts/progs are made after my post XD
Practice makes perfect!

VIP since: 6-10-2011
User avatar
comathi
Coding God
Coding God
Posts: 1242
Joined: Fri Mar 26, 2010 1:59 pm

Re: Hex Code Viewer *Tutorial*
comathi
I guess when someone starts off with a good idea, everyone wants to try it :D
5 posts Page 1 of 1
Return to “Tutorials”