By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,086 Members | 1,452 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,086 IT Pros & Developers. It's quick & easy.

display all colors

P: n/a
Is there a programatic way to iterate through all the named colors?
Something like:

HtmlTable ht = new HtmlTable();
HtmlTableRow htr;
HtmlTableCell htc;
foreach (Color c in [collection of all colors]) //I CAN'T FIND COLLECTION OF
ALL COLORS
{
htr = new HtmlTableRow();
htc = new HtmlTableCell();
htc.InnerText = c.Name;
htr.Cells.Add(htc);
ht.Rows.Add(htr);
}
phColors.Controls.Add(ht); //Display table in a placeholder control

Thanks in advance!
Mark
Nov 18 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
collection of colors from where?
Server? These would be irrelevant since they are interpreted by the client.
Client? nope....can't get em, besides, named colors can be "adjusted" I
believe. Get the #00000 values. Probably easier to just build a list of
standards though.

--
Curt Christianson
Owner/Lead Developer, DF-Software
www.Darkfalz.com
"Mark" <fi******@idonotlikejunkmail.umn.edu> wrote in message
news:Ox**************@TK2MSFTNGP12.phx.gbl...
Is there a programatic way to iterate through all the named colors?
Something like:

HtmlTable ht = new HtmlTable();
HtmlTableRow htr;
HtmlTableCell htc;
foreach (Color c in [collection of all colors]) //I CAN'T FIND COLLECTION OF ALL COLORS
{
htr = new HtmlTableRow();
htc = new HtmlTableCell();
htc.InnerText = c.Name;
htr.Cells.Add(htc);
ht.Rows.Add(htr);
}
phColors.Controls.Add(ht); //Display table in a placeholder control

Thanks in advance!
Mark

Nov 18 '05 #2

P: n/a
Here's some code I use that might give you a hand:

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
If Not IsPostBack Then
Dim strSelectedColor As String
Dim li As New ListItem
Dim enumColor As New KnownColor
Dim Colors As Array = _
[Enum].GetValues(enumColor.GetType())
DropDownList1.DataSource = Colors
DropDownList1.DataBind()
strSelectedColor = DropDownList1.Items(0).Text
li.Value = 0
li.Text = "--ALL"
DropDownList1.Items.Insert(0, li)
End If
End Sub 'Page_Load
Private Sub DropDownList1_SelectedIndexChanged _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles DropDownList1.SelectedIndexChanged
Label1.Text = DropDownList1.SelectedItem.Text
End Sub

Ken
Microsoft MVP [ASP.NET]
"Mark" <fi******@idonotlikejunkmail.umn.edu> wrote in message
news:Ox**************@TK2MSFTNGP12.phx.gbl...
Is there a programatic way to iterate through all the named colors?
Something like:

HtmlTable ht = new HtmlTable();
HtmlTableRow htr;
HtmlTableCell htc;
foreach (Color c in [collection of all colors]) //I CAN'T FIND COLLECTION
OF
ALL COLORS
{
htr = new HtmlTableRow();
htc = new HtmlTableCell();
htc.InnerText = c.Name;
htr.Cells.Add(htc);
ht.Rows.Add(htr);
}
phColors.Controls.Add(ht); //Display table in a placeholder control

Thanks in advance!
Mark


Nov 18 '05 #3

P: n/a
System.Drawing.Color has them all

"Mark" <fi******@idonotlikejunkmail.umn.edu> wrote in message news:Ox**************@TK2MSFTNGP12.phx.gbl...
Is there a programatic way to iterate through all the named colors?
Something like:

HtmlTable ht = new HtmlTable();
HtmlTableRow htr;
HtmlTableCell htc;
foreach (Color c in [collection of all colors]) //I CAN'T FIND COLLECTION OF
ALL COLORS
{
htr = new HtmlTableRow();
htc = new HtmlTableCell();
htc.InnerText = c.Name;
htr.Cells.Add(htc);
ht.Rows.Add(htr);
}
phColors.Controls.Add(ht); //Display table in a placeholder control

Thanks in advance!
Mark

Nov 18 '05 #4

P: n/a
Good points. However, let's assume that I had the same client on every
desktop, which means the colors would render the same. We're not shooting
for perfection - just a display of the available colors and their names
and/or numbers. What's the best method of iterating through the "typical"
available colors?

Thanks again.

Mark

"Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
news:uT**************@TK2MSFTNGP09.phx.gbl...
collection of colors from where?
Server? These would be irrelevant since they are interpreted by the client. Client? nope....can't get em, besides, named colors can be "adjusted" I
believe. Get the #00000 values. Probably easier to just build a list of
standards though.

--
Curt Christianson
Owner/Lead Developer, DF-Software
www.Darkfalz.com
"Mark" <fi******@idonotlikejunkmail.umn.edu> wrote in message
news:Ox**************@TK2MSFTNGP12.phx.gbl...
Is there a programatic way to iterate through all the named colors?
Something like:

HtmlTable ht = new HtmlTable();
HtmlTableRow htr;
HtmlTableCell htc;
foreach (Color c in [collection of all colors]) //I CAN'T FIND
COLLECTION OF
ALL COLORS
{
htr = new HtmlTableRow();
htc = new HtmlTableCell();
htc.InnerText = c.Name;
htr.Cells.Add(htc);
ht.Rows.Add(htr);
}
phColors.Controls.Add(ht); //Display table in a placeholder control

Thanks in advance!
Mark


Nov 18 '05 #5

P: n/a
Thanks!! This worked well. I ended up using the following code to create
an HtmlTable instance and add it to a placeholder control on my page:

HtmlTable ht = new HtmlTable();
HtmlTableRow htr;
HtmlTableCell htc;

KnownColor enumColor = new KnownColor();
Array colors = Enum.GetValues(enumColor.GetType());

bool bFirstColorFound = false;
for (int i = 0; i < colors.Length; i++)
{
string strColor = colors.GetValue(i).ToString();
if ( strColor == "AliceBlue")
{
bFirstColorFound = true;
}
if (bFirstColorFound == true)
{
htr = new HtmlTableRow();

//FIRST CELL
htc = new HtmlTableCell();
htc.InnerText = strColor ;
htr.Cells.Add(htc);

//SECOND CELL
htc = new HtmlTableCell();
htc.BgColor = strColor;
htc.InnerHtml = @"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
htr.Cells.Add(htc);

//Add row to table.
ht.Rows.Add(htr);
}
}

phColors.Controls.Add(ht);


"Ken Cox [Microsoft MVP]" <BA************@sympatico.ca> wrote in message
news:en****************@TK2MSFTNGP12.phx.gbl...
Here's some code I use that might give you a hand:

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
If Not IsPostBack Then
Dim strSelectedColor As String
Dim li As New ListItem
Dim enumColor As New KnownColor
Dim Colors As Array = _
[Enum].GetValues(enumColor.GetType())
DropDownList1.DataSource = Colors
DropDownList1.DataBind()
strSelectedColor = DropDownList1.Items(0).Text
li.Value = 0
li.Text = "--ALL"
DropDownList1.Items.Insert(0, li)
End If
End Sub 'Page_Load
Private Sub DropDownList1_SelectedIndexChanged _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles DropDownList1.SelectedIndexChanged
Label1.Text = DropDownList1.SelectedItem.Text
End Sub

Ken
Microsoft MVP [ASP.NET]
"Mark" <fi******@idonotlikejunkmail.umn.edu> wrote in message
news:Ox**************@TK2MSFTNGP12.phx.gbl...
Is there a programatic way to iterate through all the named colors?
Something like:

HtmlTable ht = new HtmlTable();
HtmlTableRow htr;
HtmlTableCell htc;
foreach (Color c in [collection of all colors]) //I CAN'T FIND COLLECTION OF
ALL COLORS
{
htr = new HtmlTableRow();
htc = new HtmlTableCell();
htc.InnerText = c.Name;
htr.Cells.Add(htc);
ht.Rows.Add(htr);
}
phColors.Controls.Add(ht); //Display table in a placeholder control

Thanks in advance!
Mark

Nov 18 '05 #6

P: n/a
And thanks for the C# conversion!

"Mark" <fi******@idonotlikejunkmail.umn.edu> wrote in message
news:uf**************@TK2MSFTNGP10.phx.gbl...
Thanks!! This worked well. I ended up using the following code to create
an HtmlTable instance and add it to a placeholder control on my page:

HtmlTable ht = new HtmlTable();
HtmlTableRow htr;
HtmlTableCell htc;

KnownColor enumColor = new KnownColor();
Array colors = Enum.GetValues(enumColor.GetType());

bool bFirstColorFound = false;
for (int i = 0; i < colors.Length; i++)
{
string strColor = colors.GetValue(i).ToString();
if ( strColor == "AliceBlue")
{
bFirstColorFound = true;
}
if (bFirstColorFound == true)
{
htr = new HtmlTableRow();

//FIRST CELL
htc = new HtmlTableCell();
htc.InnerText = strColor ;
htr.Cells.Add(htc);

//SECOND CELL
htc = new HtmlTableCell();
htc.BgColor = strColor;
htc.InnerHtml = @"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
htr.Cells.Add(htc);

//Add row to table.
ht.Rows.Add(htr);
}
}

phColors.Controls.Add(ht);


Nov 18 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.