You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Drawing;
  6. namespace Novacode
  7. {
  8. internal static class Extensions
  9. {
  10. internal static string ToHex(this Color source)
  11. {
  12. byte red = source.R;
  13. byte green = source.G;
  14. byte blue = source.B;
  15. string redHex = red.ToString("X");
  16. if (redHex.Length < 2)
  17. redHex = "0" + redHex;
  18. string blueHex = blue.ToString("X");
  19. if (blueHex.Length < 2)
  20. blueHex = "0" + blueHex;
  21. string greenHex = green.ToString("X");
  22. if (greenHex.Length < 2)
  23. greenHex = "0" + greenHex;
  24. return string.Format("{0}{1}{2}", redHex, greenHex, blueHex);
  25. }
  26. }
  27. }