Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert int to Color in Windows Forms

Tags:

c#

casting

colors

I have a value in row that equals -16777056, but how do I cast it to Color?

Something like that:

Color = (Color) Convert.ToInt32(((DataRowView)this.dataGridView1.Rows[e.RowIndex].DataBoundItem)["Color"]) })
like image 935
user278618 Avatar asked Nov 27 '22 21:11

user278618


1 Answers

Converting between colors and numbers is called color-graphemic synesthesia, and a person with this condition can be able to identify the color (or even shape or "feeling") of a number. One tricky bit here, though, is that this has never been identified in a computer (only in people). Further, this condition is generally due to genetics in people, but has been reported after psychedelic drug use. And while I would never suggest the use of illegal drugs, I guess slipping your CPU some LSD may be worth a shot.

One more difficulty is that synesthetes don't have commonality between them - that is to say that the number 6 isn't the same color to me as it is to you. So these may render differently on your computer than on mine. (Sort of like a "wow, man, how can I know that things that the color "blue" for me doesn't look like what I think "red" is for you?" But again, we're back to illegal drugs.)

That's how I'd try to convert a number into a color. That is, unless your number actually represents something useful, like an ARGB color value. In which case you can use:

Color.FromArgb(numericValue);
like image 158
Edward Thomson Avatar answered Dec 05 '22 20:12

Edward Thomson