Hi!
I’m currently learning C# and Forms, I need a way to get colors from an int variable, but not as an argb code.
In the documentation I see that color class has properties ordered from AliceBlue to YellowGreen; i need to convert 1 to AliceBlue, 2 to AntiqueWhite… or at least a way to redirect numbers from 1 to 140 to each of the colors.
Is there a way to do that?
Use reflection to discover all public get-only static properties of type Color
declared on the Colors
class.
Sort them in to a stable ordering (i.e. alphabetically).
Then you can use their position in the sorted collection as an index.
However, note that this ordering is only stable as long as MS doesn’t change anything on the Colors
class. It might be worth using this approach once to make a permanent list that you can store and recall in a file instead.
Thanks! It works perfectly! It’s for a school assignment, it shouldn’t be a problem if the colors class changes, also i don’t really need a specific order, so it’s a perfect solution!
The colors’ hexadecimal code
How do i get to the hex code from a “normal” number?
C# devs
null reference exceptions