shareFunction.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. using System;
  2. using System.Drawing;
  3. namespace SpectrumSTDEditor.BaseClass
  4. {
  5. public static class shareFunction
  6. {
  7. public static string ObtainRandomColor()
  8. {
  9. int iSeed = 10;
  10. Random ro = new Random(10);
  11. long tick = DateTime.Now.Ticks;
  12. Random ran = new Random((int)(tick & 0xffffffffL) | (int)(tick >> 32));
  13. int R = ran.Next(255);
  14. int G = ran.Next(255);
  15. int B = ran.Next(255);
  16. B = (R + G > 400) ? R + G - 400 : B;//0 : 380 - R - G;
  17. B = (B > 255) ? 255 : B;
  18. Color color=Color.FromArgb(R, G, B);
  19. return ColorTostring10(color);
  20. }
  21. public static Color string10ToColor(string lor)
  22. {
  23. int iColor = Convert.ToInt32(lor);
  24. return Color.FromArgb(iColor % 256, (iColor >> 8) % 256, (iColor >> 16) % 256);
  25. }
  26. public static string ColorTostring10(Color color)
  27. {
  28. return (((uint)color.B << 16) | (ushort)(((ushort)color.G << 8) | color.R)).ToString();
  29. }
  30. }
  31. }