Get Hex Color Code
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
What This does
All this simply does it where ever the mouse hovers it will display the hex code into a textbox and the color hoved into a picture box
Things needed:
1.timer
2.Picture box
3.textbox
Instructions:
Ok add a timer from the toolbox it will be under the Components dropdown or All Windows Forms
Add this code by either double click timer1 or right clicking it and clicking view code
now just add a textbox and a picture box and your done
sorry if i didnt explain it right lol
All this simply does it where ever the mouse hovers it will display the hex code into a textbox and the color hoved into a picture box
Things needed:
1.timer
2.Picture box
3.textbox
Instructions:
Ok add a timer from the toolbox it will be under the Components dropdown or All Windows Forms
Add this code by either double click timer1 or right clicking it and clicking view code
Code: Select all
then enable the timer and make the interval anything below 100' the 1,1 or 1x1 is the pixle so its pretty much spot on feel free to edit the 1,1
Dim a As New Drawing.Bitmap(1, 1)
'importing important stuff :P ... Dim pretty much means declare but its short for Dimension/s
Dim b As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(a)
'following mouse position to pick up color
b.CopyFromScreen(New Drawing.Point(MousePosition.X, MousePosition.Y), New Drawing.Point(0, 0), a.Size)
'Drawing to picture box 1
Dim c As Drawing.Color = a.GetPixel(0, 0)
'reading what the back color is to picture box 1
PictureBox1.BackColor = c
'writes the color hex code to the textbox
TextBox1.Text = PictureBox1.BackColor.Name
now just add a textbox and a picture box and your done

sorry if i didnt explain it right lol
You do not have the required permissions to view the files attached to this post.
Last edited by Snyper345 on Sat Mar 05, 2011 7:18 pm, edited 2 times in total.
Nice tutorial, Snyper, but can you show us how to click somewhere on the picturebox to get the hex code AND RGB values? That is what I need.
C# (Hex values and RGB values):
![Image]()
Download (.DLL):
http://www.mediafire.com/?gzdr4q8ach9i49v
A = Alpha(Transparency, 0 = invisible, 255 = solid)
R = Red
B = Blue
G = Green
Code: Select all
VB.NET (Hex values and RGB values):
public void getHexFromScreen(int coordx, int coordy, PictureBox pb, TextBox tb, TextBox tb2)
{
System.Drawing.Bitmap a = new System.Drawing.Bitmap(coordx, coordy);
System.Drawing.Graphics b = System.Drawing.Graphics.FromImage(a);
b.CopyFromScreen(new System.Drawing.Point(Control.MousePosition.X, Control.MousePosition.Y), new System.Drawing.Point(0, 0), a.Size);
System.Drawing.Color c = a.GetPixel(0, 0);
pb.BackColor = c;
tb.Text = pb.BackColor.Name.ToString();
toRGB(tb.Text);
tb2.Text = toRGB(tb.Text).ToString();
}
public System.Drawing.Color toRGB(string colorHex)
{
int red = int.Parse(colorHex.Substring(0, 2), NumberStyles.AllowHexSpecifier);
int green = int.Parse(colorHex.Substring(2, 2), NumberStyles.AllowHexSpecifier);
int blue = int.Parse(colorHex.Substring(4, 2), NumberStyles.AllowHexSpecifier);
return System.Drawing.Color.FromArgb(red, blue, green);
}
Code: Select all
Use this code in a timer as:
Public Sub getHexFromScreen(coordx As Integer, coordy As Integer, pb As PictureBox, tb As TextBox, tb2 As TextBox)
Dim a As New System.Drawing.Bitmap(coordx, coordy)
Dim b As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(a)
b.CopyFromScreen(New System.Drawing.Point(Control.MousePosition.X, Control.MousePosition.Y), New System.Drawing.Point(0, 0), a.Size)
Dim c As System.Drawing.Color = a.GetPixel(0, 0)
pb.BackColor = c
tb.Text = pb.BackColor.Name.ToString()
toRGB(tb.Text)
tb2.Text = toRGB(tb.Text).ToString()
End Sub
Public Function toRGB(colorHex As String) As System.Drawing.Color
Dim red As Integer = Integer.Parse(colorHex.Substring(0, 2), NumberStyles.AllowHexSpecifier)
Dim green As Integer = Integer.Parse(colorHex.Substring(2, 2), NumberStyles.AllowHexSpecifier)
Dim blue As Integer = Integer.Parse(colorHex.Substring(4, 2), NumberStyles.AllowHexSpecifier)
Return System.Drawing.Color.FromArgb(red, blue, green)
End Function
Code: Select all
Imports:
getHexFromScreen(1, 1, pictureBox1, textBox1, textBox2);
Code: Select all
Screenshot (Hovering over yellow border on icon):using System.Globalization;

Download (.DLL):
http://www.mediafire.com/?gzdr4q8ach9i49v
A = Alpha(Transparency, 0 = invisible, 255 = solid)
R = Red
B = Blue
G = Green
Last edited by Zulf on Sat Mar 05, 2011 7:51 pm, edited 2 times in total.
5 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023