Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / December 2005

Tip: Looking for answers? Try searching our database.

Getting the list of colors!

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sinex - 08 Dec 2005 07:06 GMT
Hi,
 I want to retrieve the list of Colors available and display them in a drop
down combo. But the Color strcture doesnt seem to have a method that returns
the list of colors. Is there an enumerator that I can use?

Sinex
Truong Hong Thi - 08 Dec 2005 07:32 GMT
There are so many colors - with 1 byte for red, 1 byte for blue, 1 byte
for green, there are over 16 millions.
- you want to get the list of 16 basic colors?
- you want to get the list of colors used by windows components (title
bar, button background, etc.)?

Thi
Truong Hong Thi - 08 Dec 2005 08:27 GMT
To get the list of all "known color", get all members of KnownColor
enum then pass to Color.GetKnownColor. Known colors contains system
colors used by windows components, if you don't want to get them, the
alternative is using reflection to get static fields of Color struct.

void Color[] GetKnowColors()
{
  KnownColor[] colors = Enum.GetValues(...);
  Color[] cs = new Color[colors.Length];
  for (...)
  {
     cs[i] = Color.GetKnownColor(colors[i]);
  }
  return cs;
}

The reflection approach not shown here.

Thi
Truong Hong Thi - 08 Dec 2005 10:59 GMT
Here is the reflection approach:

Type t = typeof(Color);
PropertyInfo[] ps = t.GetProperties(BindingFlags.Static |
BindingFlags.Public);
ArrayList colorList = new ArrayList(ps.Length);
foreach (PropertyInfo p in ps)
{
 if (p.PropertyType == t)
 {
   colorList.Add(p.GetValue(null, null));
 }
}

Now the colorList contains the list of colors defined in Color struct.

Hope it helps,
Thi
Herfried K. Wagner [MVP] - 08 Dec 2005 12:38 GMT
"Sinex" <manoj.narinder@honeywell.com> schrieb:
>  I want to retrieve the list of Colors available and display them in a
> drop
> down combo. But the Color strcture doesnt seem to have a method that
> returns
> the list of colors. Is there an enumerator that I can use?

See:

<URL:http://groups.google.de/group/microsoft.public.dotnet.languages.vb/msg/48edc75eb
973a42c
>

Signature

M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>

Truong Hong Thi - 09 Dec 2005 03:54 GMT
In the mail sent to me, the OP said he just want the list of colors
defined as static properties in Color structure (KnownColor contains
more, like ActiveBorder, ActiveCaption, etc., in fact, it includes
colors defined in either Color or SystemColors) . The reflection
approach has solved this.
Peter Oliphant - 08 Dec 2005 21:40 GMT
Just so know (and you probably already do know), this can be used to
generate 256x256x256 custom colors:

Color::FromArgb( r, g, b ) ; //  r,g,b in the range of 0 -> 255

Or even transparent colors with the first component being the alpha blend
(how transparent it is on a scale of 0 (see-through) to 255 (opaque)):

Color::FromArgb( a, r, g, b ) ;

Hence, if you wanted to display ALL possible colors that would be 4 billion
of them!

I know what you mean though, you want a list of the ones which are
standardly built into the system (e.g., Red, Green, Biege, DarkGreen, Gray,
etc.)...can't help you there...

[==P==]

PS - DirectX likes colors like this: Color::FromArgb(r,g,b).ToArgb(), which
is an integer representation of the color...

> Hi,
>  I want to retrieve the list of Colors available and display them in a
[quoted text clipped - 4 lines]
>
> Sinex

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.