I created a label and need to change the color of it programmatically to a specific RGB color code, if a certain event triggers.
I tried it like this:
statusStripTestLabel.ForeColor = new Color(128, 64, 64);
BONUS:
Set it to a RGBA color.
But I get Color does not have a constructor which accepts 3 arguments.
So how do I solve this?
statusStripTestLabel.ForeColor = Color.FromArgb(128, 64, 64); //Alpha is implicitly 255.
statusStripTestLabel.ForeColor = Color.FromArgb(255, 128, 64, 64); //Alpha is explicitly 255. You can change the value of the first parameter to specify the alpha you want.
What u are trying is somewhat right in JAVA. In c# it is,
yourComponent. ForeColor=Color. FromArgb(theARGB_Code) ;
*Note not all components support transparency
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.