wessamzeidan Posted June 10, 2004 Posted June 10, 2004 Hi, how can I get the Hexadecimal code of a color from a Color object?? Quote Proudly a Palestinian Microsoft ASP.NET MVP My Blog: wessamzeidan.net
Administrators PlausiblyDamp Posted June 10, 2004 Administrators Posted June 10, 2004 The following will display the Hex value as a string. Dim c As Color = Color.Red MessageBox.Show(c.ToArgb.ToString("X")) Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
wessamzeidan Posted June 10, 2004 Author Posted June 10, 2004 Thanks, it worked fine, but I'm always getting 'FF' before the color. For example FFE0E0E0... Quote Proudly a Palestinian Microsoft ASP.NET MVP My Blog: wessamzeidan.net
Administrators PlausiblyDamp Posted June 10, 2004 Administrators Posted June 10, 2004 It is actually converting to a full ARGB format rather than just RGB (the A is the alpha channel). If you only require the RGB components you could always mask out the A part Dim c As Color = Color.Red Dim i, j As Int32 i = c.ToArgb j = c.ToArgb i = i And &HFFFFFF MessageBox.Show(j.ToString("X")) MessageBox.Show(i.ToString("X")) the above code does the same as before but j is the full ARGB and i will just be the RGB values. Out of interest what will you be doing with the Hex values? If you plan on converting back to a colour with the Color.FromARGB() function then you are better of using the full 32-bit ARGB value. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
wessamzeidan Posted June 10, 2004 Author Posted June 10, 2004 Thanks alot, it worked..... Quote Proudly a Palestinian Microsoft ASP.NET MVP My Blog: wessamzeidan.net
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.