C# - 如何将前景色更改为自定义 RGB 值

C# - How to change Fore Color to custom RGB value

我创建了一个标签,如果某个事件触发,我需要以编程方式将其颜色更改为特定的 RGB 颜色代码。

我这样试过:

statusStripTestLabel.ForeColor = new Color(128, 64, 64);

奖金:

Set it to a RGBA color.

但是我得到了Color does not have a constructor which accepts 3 arguments.

那我该如何解决呢?

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.

你正在尝试的在 JAVA 中是正确的。 在 C# 中,

你的组件。 ForeColor=颜色。 FromArgb(theARGB_Code) ;

*注意并非所有组件都支持透明度