One way to do it would be to use reflection to read the members of the System.Drawing.Color structure.
This would be something like:
markup:
<asp:ListBox ID="listColor" runat="server" />
and the code to go with it:
PropertyInfo[] colors = typeof(System.Drawing.Colo
foreach (PropertyInfo color in colors)
{
listColor.Items.Add(new ListItem(((System.Drawing.
}
However, this is not perfect. First of all, you might want to change the colors at some point. Also, if let's say the framework version changes, you are not guaranteed that all the public static members of this structure will be just colors (that is if you consider "transparent" a color anyway).
The way that I would recommend is to define your own enumeration with the colors you want, such as:
public enum Color
{
RED,
YELLOW.
etc
}
and then bind the enum to the listbox, such as:
listColor.DataSource = Enum.GetNames(typeof(Color
listColor.DataBind();
This is the best performant way, and if gives you all the flexibility you need (you can use attributes to extend or filter).
Main Topics
Browse All Topics





by: joex911Posted on 2007-12-07 at 11:16:13ID: 20429988
Hi, use the KnownColor enumeration:
Select allOpen in new window