C# Color TableGenerate a table containing HTML colors with names. Access KnownColors.
Color table. Many HTML and system colors are available. We can enumerate these in the C# language and the ASP.NET Framework. We build a table containing all named colors, making HTML easier to write.
Note Here we see the HTML colors in a table generated using the C# language. Then we see the code that wrote the table.
Example. We use the Enum.GetNames method and the typeof operator along with the Where extension method. With Where, we remove Control colors from the output. Other articles describe these methods in depth.
Tip To compile the program, add the System.Drawing assembly to your project. When you execute it, all available colors will be printed to the Console.
And It uses the StartsWith method and LINQ extension methods. These help generate the correct output.
StartsWith, EndsWith
Discussion. Sometimes we can create our documentation directly from the code and libraries we use. This is one example. The KnownColors can be enumerated and listed. This also helps us learn about how to use this programming language.
HTML color table:
activeborder activecaption activecaptiontext aliceblue antiquewhite appworkspace aqua aquamarine azure beige bisque black blanchedalmond blue blueviolet brown burlywood buttonface buttonhighlight buttonshadow cadetblue chartreuse chocolate coral cornflowerblue cornsilk crimson cyan darkblue darkcyan darkgoldenrod darkgray darkgreen darkkhaki darkmagenta darkolivegreen darkorange darkorchid darkred darksalmon darkseagreen darkslateblue darkslategray darkturquoise darkviolet deeppink deepskyblue desktop dimgray dodgerblue firebrick floralwhite forestgreen fuchsia gainsboro ghostwhite gold goldenrod gradientactivecaption gradientinactivecaption gray graytext green greenyellow highlight highlighttext honeydew hotpink hottrack inactiveborder inactivecaption inactivecaptiontext indianred indigo info infotext ivory khaki lavender lavenderblush lawngreen lemonchiffon lightblue lightcoral lightcyan lightgoldenrodyellow lightgray lightgreen lightpink lightsalmon lightseagreen lightskyblue lightslategray lightsteelblue lightyellow lime limegreen linen magenta maroon mediumaquamarine mediumblue mediumorchid mediumpurple mediumseagreen mediumslateblue mediumspringgreen mediumturquoise mediumvioletred menu menubar menuhighlight menutext midnightblue mintcream mistyrose moccasin navajowhite navy oldlace olive olivedrab orange orangered orchid palegoldenrod palegreen paleturquoise palevioletred papayawhip peachpuff peru pink plum powderblue purple red rosybrown royalblue saddlebrown salmon sandybrown scrollbar seagreen seashell sienna silver skyblue slateblue slategray snow springgreen steelblue tan teal thistle tomato transparent turquoise violet wheat white whitesmoke window windowframe windowtext yellow yellowgreen
Summary. This table contains the KnownColors from the System.Drawing namespace. Next we saw the console program that generates the table. A color sheet can be useful for selecting named colors for Internet articles.
using System; using System.Drawing; using System.Linq; class Program { static void Main() { // Get enum strings and order them by name. // Remove Control colors. foreach (string c in Enum.GetNames(typeof(KnownColor)).Where( item => !item.StartsWith("Control")).OrderBy(item => item)) { // Write table row. Console.WriteLine("<b style=background:{0}>{1}</b>", c.ToLower(), c.ToLower().PadRight(20)); } } }
© 2007-2022 sam allen.
see site info on the changelog.