From: 011netservice@gmail.com Date: 2022-04-24 Subject: Color.txt ---------- 20200826 public static void MyColorMemo() { Color C11 = Color.FromArgb(1, 2, 3); // {Name=ff010203, ARGB=(255, 1, 2, 3)}, alpha=0xFF 完全不透明 fully opaque Color C12 = Color.FromArgb(0x1, 0x2, 0x3); // {Name=ff010203, ARGB=(255, 1, 2, 3)} Color C13 = Color.FromArgb(0xFF, 1, 2, 3); // {Name=ff010203, ARGB=(255, 1, 2, 3)} Color C14 = Color.FromArgb(0, 1, 2, 3); // {Name=10203, ARGB=(0, 1, 2, 3)}, alpha=0x0 透明 Color C15 = Color.FromArgb(0x010203); // {Name=10203, ARGB=(0, 1, 2, 3)}, alpha=0 透明. Color C21 = ColorTranslator.FromOle(0x010203); // {Name=ff030201, ARGB=(255, 3, 2, 1)}, FromOle() 都是完全不透明 fully opaque Color C22 = ColorTranslator.FromOle(0x030201); // {Name=ff010203, ARGB=(255, 1, 2, 3)} Color C31 = ColorTranslator.FromWin32(0x010203); // {Name=ff030201, ARGB=(255, 3, 2, 1)} Color C32 = ColorTranslator.FromWin32(0x010203); // {Name=ff030201, ARGB=(255, 3, 2, 1)} byte[] ba11 = BitConverter.GetBytes(C11.ToArgb()); // (3, 2, 1, 255) byte[] ba21 = BitConverter.GetBytes(ColorTranslator.ToOle(C21)); // (3, 2, 1, 0) // ToOle() 都是透明 alpha = 0. byte[] ba31 = BitConverter.GetBytes(ColorTranslator.ToOle(C31)); // (3, 2, 1, 0) // Html Colors, 共16色, 都不透明. // The W3C HTML and CSS standards have listed only 16 valid color names: // aqua(cyan), black, blue, fuchsia, gray, green, lime, maroon, navy, olive, purple, red, silver, teal, white, and yellow. Color C40 = ColorTranslator.FromHtml("aqua"); // #00FFFF, 水色. (青色 cyan) Color C41 = ColorTranslator.FromHtml("black"); // #000000, 黑色. Color C42 = ColorTranslator.FromHtml("blue"); // #0000FF, 藍色. Color C43 = ColorTranslator.FromHtml("fuchsia"); // #FF00FF, 紫紅色. (粉紅色) Color C44 = ColorTranslator.FromHtml("gray"); // #808080, 灰色. Color C45 = ColorTranslator.FromHtml("green"); // #008000, 綠色 Color C46 = ColorTranslator.FromHtml("lime"); // #00FF00, 檸檬色. (青綠色) Color C47 = ColorTranslator.FromHtml("maroon"); // #800000, 栗色. (深紫色) Color C48 = ColorTranslator.FromHtml("navy"); // #000080, 海軍色. (深藍色) Color C49 = ColorTranslator.FromHtml("olive"); // #808000, 橄欖色. (咖啡色) Color C4a = ColorTranslator.FromHtml("purple"); // #800080, 紫色. Color C4b = ColorTranslator.FromHtml("red"); // #FF0000, 紅色. Color C4c = ColorTranslator.FromHtml("silver"); // #C0C0C0, 銀色. (淺灰色) Color C4d = ColorTranslator.FromHtml("teal"); // #008080, 藍綠色. Color C4e = ColorTranslator.FromHtml("white"); // #FFFFFF, 白色. Color C4f = ColorTranslator.FromHtml("yellow"); // #FFFF00, 黃色. // system colors // 以下列出對應 Html Colors 的顏色. Color C50 = Color.FromKnownColor(KnownColor.Aqua); // #00FFFF, 水色. (青色 cyan) Color C51 = Color.FromKnownColor(KnownColor.Black); // #000000, 黑色. Color C52 = Color.FromKnownColor(KnownColor.Blue); // #0000FF, 藍色. Color C53 = Color.FromKnownColor(KnownColor.Fuchsia); // #FF00FF, 紫紅色. (粉紅色) Color C54 = Color.FromKnownColor(KnownColor.Gray); // #808080, 灰色. Color C55 = Color.FromKnownColor(KnownColor.Green); // #008000, 綠色 Color C56 = Color.FromKnownColor(KnownColor.Lime); // #00FF00, 檸檬色. (青綠色) Color C57 = Color.FromKnownColor(KnownColor.Maroon); // #800000, 栗色. (深紫色) Color C58 = Color.FromKnownColor(KnownColor.Navy); // #000080, 海軍色. (深藍色) Color C59 = Color.FromKnownColor(KnownColor.Olive); // #808000, 橄欖色. (咖啡色) Color C5a = Color.FromKnownColor(KnownColor.Purple); // #800080, 紫色. Color C5b = Color.FromKnownColor(KnownColor.Red); // #FF0000, 紅色. Color C5c = Color.FromKnownColor(KnownColor.Silver); // #C0C0C0, 銀色. (淺灰色) Color C5d = Color.FromKnownColor(KnownColor.Teal); // #008080, 藍綠色. Color C5e = Color.FromKnownColor(KnownColor.White); // #FFFFFF, 白色. Color C5f = Color.FromKnownColor(KnownColor.Yellow); // #FFFF00, 黃色. // 直接取用更簡單: Color C60 = Color.Aqua; // #00FFFF, 水色. (青色 cyan) Color C61 = Color.Black; // #000000, 黑色. Color C62 = Color.Blue; // #0000FF, 藍色. Color C63 = Color.Fuchsia; // #FF00FF, 紫紅色. (粉紅色) Color C64 = Color.Gray; // #808080, 灰色. Color C65 = Color.Green; // #008000, 綠色 Color C66 = Color.Lime; // #00FF00, 檸檬色. (青綠色) Color C67 = Color.Maroon; // #800000, 栗色. (深紫色) Color C68 = Color.Navy; // #000080, 海軍色. (深藍色) Color C69 = Color.Olive; // #808000, 橄欖色. (咖啡色) Color C6a = Color.Purple; // #800080, 紫色. Color C6b = Color.Red; // #FF0000, 紅色. Color C6c = Color.Silver; // #C0C0C0, 銀色. (淺灰色) Color C6d = Color.Teal; // #008080, 藍綠色. Color C6e = Color.White; // #FFFFFF, 白色. Color C6f = Color.Yellow; // #FFFF00, 黃色. Color Wait = C11; // C11 "{Name=ff010203, ARGB=(255, 1, 2, 3)}" System.Drawing.Color // C12 "{Name=ff010203, ARGB=(255, 1, 2, 3)}" System.Drawing.Color // C13 "{Name=ff010203, ARGB=(255, 1, 2, 3)}" System.Drawing.Color // C14 "{Name=10203, ARGB=(0, 1, 2, 3)}" System.Drawing.Color // C15 "{Name=10203, ARGB=(0, 1, 2, 3)}" System.Drawing.Color // C21 "{Name=ff030201, ARGB=(255, 3, 2, 1)}" System.Drawing.Color // C22 "{Name=ff010203, ARGB=(255, 1, 2, 3)}" System.Drawing.Color // C31 "{Name=ff030201, ARGB=(255, 3, 2, 1)}" System.Drawing.Color // C32 "{Name=ff030201, ARGB=(255, 3, 2, 1)}" System.Drawing.Color // C40 "{Name=Aqua, ARGB=(255, 0, 255, 255)}" System.Drawing.Color // C41 "{Name=Black, ARGB=(255, 0, 0, 0)}" System.Drawing.Color // C42 "{Name=Blue, ARGB=(255, 0, 0, 255)}" System.Drawing.Color // C43 "{Name=Fuchsia, ARGB=(255, 255, 0, 255)}" System.Drawing.Color // C44 "{Name=Gray, ARGB=(255, 128, 128, 128)}" System.Drawing.Color // C45 "{Name=Green, ARGB=(255, 0, 128, 0)}" System.Drawing.Color // C46 "{Name=Lime, ARGB=(255, 0, 255, 0)}" System.Drawing.Color // C47 "{Name=Maroon, ARGB=(255, 128, 0, 0)}" System.Drawing.Color // C48 "{Name=Navy, ARGB=(255, 0, 0, 128)}" System.Drawing.Color // C49 "{Name=Olive, ARGB=(255, 128, 128, 0)}" System.Drawing.Color // C4a "{Name=Purple, ARGB=(255, 128, 0, 128)}" System.Drawing.Color // C4b "{Name=Red, ARGB=(255, 255, 0, 0)}" System.Drawing.Color // C4c "{Name=Silver, ARGB=(255, 192, 192, 192)}" System.Drawing.Color // C4d "{Name=Teal, ARGB=(255, 0, 128, 128)}" System.Drawing.Color // C4e "{Name=White, ARGB=(255, 255, 255, 255)}" System.Drawing.Color // C4f "{Name=Yellow, ARGB=(255, 255, 255, 0)}" System.Drawing.Color // C50 "{Name=Aqua, ARGB=(255, 0, 255, 255)}" System.Drawing.Color // C51 "{Name=Black, ARGB=(255, 0, 0, 0)}" System.Drawing.Color // C52 "{Name=Blue, ARGB=(255, 0, 0, 255)}" System.Drawing.Color // C53 "{Name=Fuchsia, ARGB=(255, 255, 0, 255)}" System.Drawing.Color // C54 "{Name=Gray, ARGB=(255, 128, 128, 128)}" System.Drawing.Color // C55 "{Name=Green, ARGB=(255, 0, 128, 0)}" System.Drawing.Color // C56 "{Name=Lime, ARGB=(255, 0, 255, 0)}" System.Drawing.Color // C57 "{Name=Maroon, ARGB=(255, 128, 0, 0)}" System.Drawing.Color // C58 "{Name=Navy, ARGB=(255, 0, 0, 128)}" System.Drawing.Color // C59 "{Name=Olive, ARGB=(255, 128, 128, 0)}" System.Drawing.Color // C5a "{Name=Purple, ARGB=(255, 128, 0, 128)}" System.Drawing.Color // C5b "{Name=Red, ARGB=(255, 255, 0, 0)}" System.Drawing.Color // C5c "{Name=Silver, ARGB=(255, 192, 192, 192)}" System.Drawing.Color // C5d "{Name=Teal, ARGB=(255, 0, 128, 128)}" System.Drawing.Color // C5e "{Name=White, ARGB=(255, 255, 255, 255)}" System.Drawing.Color // C5f "{Name=Yellow, ARGB=(255, 255, 255, 0)}" System.Drawing.Color // C60 "{Name=Aqua, ARGB=(255, 0, 255, 255)}" System.Drawing.Color // C61 "{Name=Black, ARGB=(255, 0, 0, 0)}" System.Drawing.Color // C62 "{Name=Blue, ARGB=(255, 0, 0, 255)}" System.Drawing.Color // C63 "{Name=Fuchsia, ARGB=(255, 255, 0, 255)}" System.Drawing.Color // C64 "{Name=Gray, ARGB=(255, 128, 128, 128)}" System.Drawing.Color // C65 "{Name=Green, ARGB=(255, 0, 128, 0)}" System.Drawing.Color // C66 "{Name=Lime, ARGB=(255, 0, 255, 0)}" System.Drawing.Color // C67 "{Name=Maroon, ARGB=(255, 128, 0, 0)}" System.Drawing.Color // C68 "{Name=Navy, ARGB=(255, 0, 0, 128)}" System.Drawing.Color // C69 "{Name=Olive, ARGB=(255, 128, 128, 0)}" System.Drawing.Color // C6a "{Name=Purple, ARGB=(255, 128, 0, 128)}" System.Drawing.Color // C6b "{Name=Red, ARGB=(255, 255, 0, 0)}" System.Drawing.Color // C6c "{Name=Silver, ARGB=(255, 192, 192, 192)}" System.Drawing.Color // C6d "{Name=Teal, ARGB=(255, 0, 128, 128)}" System.Drawing.Color // C6e "{Name=White, ARGB=(255, 255, 255, 255)}" System.Drawing.Color // C6f "{Name=Yellow, ARGB=(255, 255, 255, 0)}" System.Drawing.Color // Wait "{Name=0, ARGB=(0, 0, 0, 0)}" System.Drawing.Color ///// ///// 常用顏色 ///// 20200109, 還是 Follow ConsoleColor in .net 4.0: ///// //public enum ZColorNo //{ // // Win32 defines: // //Black = 0x0000, // //Blue = 0x0001, // //Green = 0x0002, // //Cyan = 0x0003, // //Red = 0x0004, // //Violet = 0x0005, // //Yellow = 0x0006, // //White = 0x0007, // //Intensified = 0x0008, // //Normal = White, // //BlackBG = 0x0000, // //BlueBG = 0x0010, // //GreenBG = 0x0020, // //CyanBG = 0x0030, // //RedBG = 0x0040, // //VioletBG = 0x0050, // //YellowBG = 0x0060, // //WhiteBG = 0x0070, // //IntensifiedBG = 0x0080, // //Underline = 0x4000, // //ReverseVideo = unchecked((short)0x8000), // // ConsoleColor in .net 4.0: // //Black = 0, // //DarkBlue = 1, // //DarkGreen = 2, // //DarkCyan = 3, // //DarkRed = 4, // //DarkMagenta = 5, // //DarkYellow = 6, // //Gray = 7, // //DarkGray = 8, // //Blue = 9, // //Green = 10, // //Cyan = 11, // //Red = 12, // //Magenta = 13, // //Yellow = 14, // //White = 15 // // 只要這幾個常用的就好, 並且可以直接對應到 Win32 跟 ConsoleColor 的顏色編號. // //Black = 0x0000, // //Blue = 0x0001, // //Green = 0x0002, // //Cyan = 0x0003, // //Red = 0x0004, // //Violet = 0x0005, // //Yellow = 0x0006, // //White = 0x0007 // // 20200109, 還是 Follow ConsoleColor in .net 4.0: // Black = 0, // DarkBlue = 1, // DarkGreen = 2, // DarkCyan = 3, // DarkRed = 4, // DarkMagenta = 5, // DarkYellow = 6, // Gray = 7, // DarkGray = 8, // Blue = 9, // Green = 10, // Cyan = 11, // Red = 12, // Magenta = 13, // Yellow = 14, // White = 15 //} } ---------- 20200826 Before: private void ShowPropertiesOfSlateBlue(PaintEventArgs e) { Color slateBlue = Color.FromName("SlateBlue"); byte g = slateBlue.G; byte b = slateBlue.B; byte r = slateBlue.R; byte a = slateBlue.A; string text = String.Format("Slate Blue has these ARGB values: Alpha:{0}, " + "red:{1}, green: {2}, blue {3}", new object[]{a, r, g, b}); e.Graphics.DrawString(text, new Font(this.Font, FontStyle.Italic), new SolidBrush(slateBlue), new RectangleF(new PointF(0.0F, 0.0F), this.Size)); } private void DisplayKnownColors(PaintEventArgs e) { this.Size = new Size(650, 550); // Get all the values from the KnownColor enumeration. System.Array colorsArray = Enum.GetValues(typeof(KnownColor)); KnownColor[] allColors = new KnownColor[colorsArray.Length]; Array.Copy(colorsArray, allColors, colorsArray.Length); // Loop through printing out the values' names in the colors // they represent. float y = 0; float x = 10.0F; for(int i = 0; i < allColors.Length; i++) { // If x is a multiple of 30, start a new column. if (i > 0 && i % 30 == 0) { x += 105.0F; y = 15.0F; } else { // Otherwise, increment y by 15. y += 15.0F; } // Create a custom brush from the color and use it to draw // the brush's name. SolidBrush aBrush = new SolidBrush(Color.FromName(allColors[i].ToString())); e.Graphics.DrawString(allColors[i].ToString(), this.Font, aBrush, x, y); // Dispose of the custom brush. aBrush.Dispose(); } } public void FromArgb2(PaintEventArgs e) { Graphics g = e.Graphics; // Opaque colors (alpha value defaults to 255 -- max value). Color red = Color.FromArgb(255, 0, 0); Color green = Color.FromArgb(0, 255, 0); Color blue = Color.FromArgb(0, 0, 255); // Solid brush initialized to red. SolidBrush myBrush = new SolidBrush(red); int alpha; // x coordinate of first red rectangle int x = 50; // y coordinate of first red rectangle int y = 50; // Fill rectangles with red, varying the alpha value from 25 to 250. for (alpha = 25; alpha <= 250; alpha += 25) { myBrush.Color = Color.FromArgb(alpha, red); g.FillRectangle(myBrush, x, y, 50, 100); g.FillRectangle(myBrush, x, y + 250, 50, 50); x += 50; } // x coordinate of first green rectangle. x = 50; // y coordinate of first green rectangle. y += 50; // Fill rectangles with green, varying the alpha value from 25 to 250. for (alpha = 25; alpha <= 250; alpha += 25) { myBrush.Color = Color.FromArgb(alpha, green); g.FillRectangle(myBrush, x, y, 50, 150); x += 50; } // x coordinate of first blue rectangle. x = 50; // y coordinate of first blue rectangle. y += 100; // Fill rectangles with blue, varying the alpha value from 25 to 250. for (alpha = 25; alpha <= 250; alpha += 25) { myBrush.Color = Color.FromArgb(alpha, blue); g.FillRectangle(myBrush, x, y, 50, 150); x += 50; } } public void KnownColorBrightnessExample1(PaintEventArgs e) { Graphics g = e.Graphics; // Color structures. One is a variable used for temporary storage. The other // is a constant used for comparisons. Color someColor = Color.FromArgb(0); Color redShade = Color.FromArgb(255, 200, 0, 100); // Array to store KnownColor values that match the brightness of the // redShade color. KnownColor[] colorMatches = new KnownColor[15]; // Number of matches found. int count = 0; // Iterate through the KnownColor enums until 15 matches are found. for (KnownColor enumValue = 0; enumValue <= KnownColor.YellowGreen && count < 15; enumValue++) { someColor = Color.FromKnownColor(enumValue); if (someColor.GetBrightness() == redShade.GetBrightness()) colorMatches[count++] = enumValue; } // Display the redShade color and its argb value. SolidBrush myBrush1 = new SolidBrush(redShade); Font myFont = new Font("Arial", 12); int x = 20; int y = 20; someColor = redShade; g.FillRectangle(myBrush1, x, y, 100, 30); g.DrawString(someColor.ToString(), myFont, Brushes.Black, x + 120, y); // Iterate through the matches that were found and display each color that // Corresponds with the enum value in the array. also display the name of // The KnownColor. for (int i = 0; i < count; i++) { y += 40; someColor = Color.FromKnownColor(colorMatches[i]); myBrush1.Color = someColor; g.FillRectangle(myBrush1, x, y, 100, 30); g.DrawString(someColor.ToString(), myFont, Brushes.Black, x + 120, y); } }