Specify number get color

  • Thread starter Thread starter Jim McGivney - Office
  • Start date Start date
J

Jim McGivney - Office

Is there a way to specify a number (0-141) to obtain one of the system
colors ?
Pen pen = new Pen(ColorNum);
where ColorNum is a method to specify a color by its enumeration value.
Thanks,
Jim
 
Have you considered using the Pens class and using a predesigned pen?
There are pens defined already for the system colors. For example:
Pens.Blue

Otherwise, you can select the color by name:

Pen pen = new Pen(Color.Blue)

Be sure to dispose of your pens when you are done using them.
 
I think Jim wanted a system color, like ButtonFace, ActiveCaption...In the
framework, these colors are called KnownColor and can be obtained like this
:

Color c = Color.FromKnownColor(KnownColor.ButtonFace)

which can then be used in the Pen constructor.

BTW, why do you need to dispose the pens ? It's managed. The Pen destructor
releases its resources.

Fabien
 
Jim,
In addition to the other comments:

Have you tried Color.FromKnownColor?

KnownColor ColorNum = KnownColor.Blue;
Pen pen = new Pen(Color.FromKnownColor(ColorNum));

Hope this helps
Jay

| Is there a way to specify a number (0-141) to obtain one of the system
| colors ?
| Pen pen = new Pen(ColorNum);
| where ColorNum is a method to specify a color by its enumeration value.
| Thanks,
| Jim
|
|
 
Back
Top