开发者

How to change background color in C#?

开发者 https://www.devze.com 2023-02-13 00:51 出处:网络
I\' have form that user can select a color. I\'m writing that color to my database for use other forms too.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消