12345678910111213141516171819202122232425262728293031323334 |
- using System;
- using System.Drawing;
- namespace SpectrumSTDEditor.BaseClass
- {
- public static class shareFunction
- {
- public static string ObtainRandomColor()
- {
- int iSeed = 10;
- Random ro = new Random(10);
- long tick = DateTime.Now.Ticks;
- Random ran = new Random((int)(tick & 0xffffffffL) | (int)(tick >> 32));
- int R = ran.Next(255);
- int G = ran.Next(255);
- int B = ran.Next(255);
- B = (R + G > 400) ? R + G - 400 : B;//0 : 380 - R - G;
- B = (B > 255) ? 255 : B;
- Color color=Color.FromArgb(R, G, B);
- return ColorTostring10(color);
- }
- public static Color string10ToColor(string lor)
- {
- int iColor = Convert.ToInt32(lor);
- return Color.FromArgb(iColor % 256, (iColor >> 8) % 256, (iColor >> 16) % 256);
- }
- public static string ColorTostring10(Color color)
- {
- return (((uint)color.B << 16) | (ushort)(((ushort)color.G << 8) | color.R)).ToString();
- }
- }
- }
|