Для работы вам необходимо подключить следующие пространства имен:
using System.Collections.Generic; using System.Drawing;
Вывод списка цветов в List:
private ListGetColors() { //create a generic list of strings List colors = new List (); //get the color names from the Known color enum string[] colorNames = Enum.GetNames(typeof(KnownColor)); //iterate thru each string in the colorNames array foreach (string colorName in colorNames) { //cast the colorName into a KnownColor KnownColor knownColor = (KnownColor)Enum.Parse(typeof(KnownColor), colorName); //check if the knownColor variable is a System color if (knownColor > KnownColor.Transparent) { //add it to our list colors.Add(colorName); } } //return the color list return colors; }
Вывод списка цветов в listBox:
private void GetColorsList()
{
//get the color names from the Known color enum
string[] colorNames = Enum.GetNames(typeof(KnownColor));
//iterate thru each string in the colorNames array
foreach (string colorName in colorNames)
{
//cast the colorName into a KnownColor
KnownColor knownColor = (KnownColor)Enum.Parse(typeof(KnownColor), colorName);
//check if the knownColor variable is a System color
if (knownColor > KnownColor.Transparent)
{
listBox1.Items.Add(colorName);
}
}
}
Вот что получилось у меня:
0.00 (0%) 0 votes










