I' have form that user can select a color. I'm writing that color to my database for use other forms too.
When I'm saving a color to database it's looks like this;
Color [A=255, R=255, G=128, B=64]
How 开发者_JAVA百科can i convert this and use as background color?
You should store the value from Color.ToArgb()
in the database and Color.FromArgb()
when you read from the database.
Assuming this is a WinForms application use Color.FromArgb()
:
BackColor = Color.FromArgb(a, r, g, b);
int A = 255; int R=255; int G = 128; int B=64;
System.Drawing.Color c = System.Drawing.Color.FromArgb( A, R, G, B);
I you write the color to the dbase as a string then you can use the ColorConverter class, ConvertToString() and ConvertFromString() methods. Or you can store it as an integer, use the Color.ToArgb() and FromArgb() methods.
精彩评论