简体   繁体   中英

How to change background color in C#?

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 can i convert this and use as background color?

假设这是一个 WinForms 应用程序,使用Color.FromArgb()

BackColor = Color.FromArgb(a, r, g, b);

当您从数据库中读取时,您应该将Color.ToArgb()中的值存储在数据库中,并将Color.FromArgb()的值存储在数据库中。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM