Sorry Patrice, this is a web page. My intention is to display the
color as forecolor with the hex value as the value of the dropdown.
Could give something such as :
Color[] colors={System.Drawing.Color.Red,System.Drawing.Color.Green};
foreach(Color color in colors)
{
ListItem li=new ListItem();
li.Attributes.Add("style","color:#"+String.Format("{0:x}",color.ToArgb()).Substring(2));
li.Text=String.Format("{0:X}",color.ToArgb()).Substring(2);
li.Value = li.Text;
ddl.Items.Add(li);
}
ddl being an ASP.NET DropDownList...
You can use the a 0:X placeholder to convert a value to an hexa value (I use
Substring to keep only RGB values and drop the Alpha component). Using the
Attributes collection, you can add the appropriate style to set the color
even if the ListItem class has no explicit properties for this...