.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Windows Form Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

How to convert a RGB color to Hexa equivalent?

Posted By:Jean Paul       Posted Date: September 29, 2010    Points: 10    Category: Windows Form Controls    URL: http://www.dotnetspark.com  

Usage: string hexaColor = ColorToHexaColor(Color.Red);
 

        public string ColorToHexaColor(Color color)
        {
            return "#" + Get2CharHexa(color.R) + Get2CharHexa(color.G) + Get2CharHexa(color.B);
        }

        private string Get2CharHexa(byte b)
        {
            string s = b.ToString("X");
            if (s.Length == 1)
                s = "0" + s;

            return s;
        }

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend