Color as a number (colorindexing ?)

Antoine

Regular
Joined
Aug 12, 2003
Messages
58
Location
The Netherlands
Hello,

In VB.net are a lot of predefined system colors. Like Aliceblue, antiquewhite, aqua, etc. etc.

Is it possible in some way to define colors in your project with number ? So to say not:

button.backcolor = system.drawing.color.aqua

But something like

button.backcolor = system.drawing.color(2) (where 2 stands for aqua) ?

IS this possible is some way ? It would greatly affect the size of my code :)

Thanks in advance !
Antoine
 
PlausiblyDamp said:
Wouldn't this just make the code less readable in the long run? Also why would this necessarily result in smaller code?

If hes got lots of colour code i expect it'd mount up, but he'd have a have a serious amount of code dealing with colours.

Code size shouldn't really be a concern. if you can make the code smaller by making longer functions into smaller ones thats usually good because its code re-use. Smaller code in itself is a pointless goal if it takes longer to read. Afterall the compiler really doesn't care how long the code it only how correct it is, and the more direct you are in your code the less instructions dealing with indirection will be created (before any compiler optimisation of course).
 
What is your goal?

Antoine said:
Is it possible in some way to define colors in your project with number ?

Is your goal to be able to cycle through colors for users to pick from, without having to know the "color.auqa" value and so forth? The system refers to colors as color instances or static values, but not as numeric values in the traditional sense. Can you give a short example of what you are trying to do and a short code segment that you propose? I ran into the same problem with colors until I became more familiar with .NET and object-oriented programming.
 
Colors are Structures, and in each color structure, you can get any of the list of available colors.

Here are two ways to use a number to get a color.
The first way would be to use Color.FromArgb(number).
The number you specify will be transformed into a color. It is easier to understand your number if you put it in the function by a hexadecimal value.
&H3258A288
This will be a color with &H88 in the Red channel, &HA2 in the Green channel, and &H58 in the Blue channel, and &H32 in the Alpha channel.

The other would be to make an array of color structures. :)
 
Back
Top